distinguish between keyboard's Real and Virtual key presses

允我心安 提交于 2019-12-08 07:27:27

问题


I'm writing a program in C#, that have to simulate keyboard's key press commands.

The problem is - I need to simulate "realistic" keyboard button clicks, not the fake ones. For example, as far as I understand:

  • when user presses any button on the keyboard - the signal is sent via USB, and then proceed via keyboard's driver.

  • when API's are used (SendInput, SendKeys, KeyBoardEvent, or whatever) - we bypass USB and driver, so basically these kind of presses can be tracked via global hook method..

How do you simulate Realistic key presses?

  • I don't have knowledge in C++ so writing a custom driver is not an option.

  • I don't mind using microcontrollers or any additional hardware "solutions", as long as it's cheap..

  • maybe it's possible to connect two PC's via USB cable for the purpose of sending realistic keyboard button press signals from PC2 to PC1?

so what's the method?


回答1:


You can identify keyboard event sent with SendInput() with global keyboard hook(WH_KEYBOARD_LL). It's callback method LowLevelKeyboardProc recieves KBDLLHOOKSTRUCT as a parameter.

If LLKHF_INJECTED flag is set in KBDLLHOOKSTRUCT.flags keyboard event was injected with SendInput().



来源:https://stackoverflow.com/questions/10341525/distinguish-between-keyboards-real-and-virtual-key-presses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!