0

I am programmatically generating keypressed event in WPF using this code:

 new KeyEventArgs(Keyboard.PrimaryDevice,
        Keyboard.PrimaryDevice.ActiveSource,
        0, args.Key)
    {
       RoutedEvent = Keyboard.KeyDownEvent
    }

where args.Key is the argument of the KeyUphandler of my WPF usercontrol.

Further I am trying to convert this WPF Key into a Win32 Virtual-Key using KeyInterop.VirtualKeyFromKey method like this:

var keyData = (Keys)KeyInterop.VirtualKeyFromKey(e.Key == Key.System ? e.SystemKey : e.Key);

This method is working fine for normal keys but it is not working for F10 key ( I am getting keydata as None for F10). Any help would be great.

Mohd Ahmed
  • 1,422
  • 13
  • 27
  • Pls check here: http://stackoverflow.com/questions/2103497/detecting-the-user-pressing-f10-in-wpf – Whencesoever Jan 21 '15 at 13:24
  • I have already seen that article. The problem I am facing is that I am creating the new object of KeyEventArgs and then I am unable to convert WPF key to virtual key using KeyInterop.VirtualKeyFromKey method. – Mohd Ahmed Jan 21 '15 at 13:29
  • 5
    Rather than attempt to fake key presses, you are better off calling the code that would be called upon those specific key presses. – Sheridan Jan 21 '15 at 13:31

0 Answers0