tags:

views:

45

answers:

1

Hi,

I'm currently writing in C# wpf and I would like to imitate the action of clicking a button by the user pressing a key.

private void abuttonispressed(object sender, System.Windows.Input.KeyEventArgs e)
                {
                    if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.S)) 
                    {
                        //click event is raised here
                    } 


                }

It's vital that not only the code of that button is run but also the visual 'clicking' of the button. I read about this and suggestions like performclick were made but performclick is not a known method for the button somehow...

Any ideas?

+1  A: 

I don't know the right answer, but would start playing from here:

private void abuttonispressed(object sender, System.Windows.Input.KeyEventArgs e)
{
    if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.S)) 
    {
        //click event is raised here
        button1.Focus();
        button1.RaiseEvent(new RoutedEventArgs(Button.ClickEvent, button1));
    } 
}
Viktor Jevdokimov
Thanks that's great
internetmw