开发者

Convert KeyEventArgs to KEYDBINPUT struct

I am working on a networked system (in C#) where on one computer I receive keyboard input via a low level hook and then transmit the input to another computer where it has to be injected.

The hook delivers the keyboard input in a KeyEventArgs class. To inject it into the target computer I need to use a KEYBDINPUT struct with SendInput.

There does not seem to be an easy match between KeyEventArgs.KeyCode or KeyValue and KEYBDINPUT.wVk and wScan. I also tried MapVirtualKey in some combinations.

Alternatively, I could convert KeyEventArgs into windows key messages (WM_KEYUP/DOWN with wParam and lParam) on the 开发者_运维百科source computer but I am facing similar difficulties.

Can anybody here help out with either scenario?


You may want to look at the recent answer here where I suggest the use of InputSimulator as an alternative to other low level work. This uses the Win32 SendInput API directly.

This uses VirtualKeyCode, so since you have KeyEventArgs you can just use the KeyValue property:

InputSimulator.SimulateKeyPress(keyEventArgs.KeyValue);

If you only have a System.Key you can convert to a VirtualKey

http://msdn.microsoft.com/en-us/library/system.windows.input.keyinterop.virtualkeyfromkey.aspx

How can I convert 'System.Windows.Input.Key' to 'System.Windows.Forms.Keys'?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜