Simulate keypress by code

Jayme65

Active member
Joined
Apr 5, 2011
Messages
35
Programming Experience
Beginner
Hi,

I have an application which is entirely driven by keyboard (no mouse!).
In that application there's a "complex" menu where people browse buttons with...the keyboard.
Until then, browsing the buttons was done with the arrows key. I had nothing to code as, by default, this is properly managed by windows!
The "problem" is now that the users wanted the default keys of all my application to be customized!
One could for instance map the directional keys to 8(up), 5(down), 4(left), 6(right).

The best would be to simulated a keypress when those keys are pressed.
How should I please proceed, for instance, to send a "Arrow Up" key pressed event to the system...when the "8" key is pressed!

Hope that I'm clear enought..and thanks for your help!!!
 
Lotok,

Thanks very much for your reply!
I've tried to get more info on this "e.ImeProcessedKey" and how to use it...and didn't find a lot of info!
Would you please have some more time to complete your answer a little, giving me the explanation on how to use it to get (for instance) a "Arrow Up" keydown...when the"8" key is pressed!

Thanks very much for your help!
 
You havr to reference Microsoft.Windows.Forms Assembly in the WPF application.

Then you can do
        If e.Key = Key.NumPad8 Then
            System.Windows.Forms.SendKeys.SendWait("{UP}")
        End If


You can pretty much send any keypress in this manner, except I had some issues with {TAB}
Apologies, I was barking up the wrong tree with e.ImeProcessedKey, I hadn't tested in in VS earlier. You will find this helpful: SendKeys Class (System.Windows.Forms)
 
Last edited:
Back
Top