3

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?

Chuck Callebs
  • 16,293
  • 8
  • 56
  • 71
Alex
  • 4,607
  • 9
  • 61
  • 99
  • I can't understand what you mean here. If you are prepared to have a hardware solution, isn't that just a keyboard? – David Heffernan Apr 26 '12 at 21:17
  • Keyboard events injected with SendInput() are indistinguishable from keyboard events generated by the driver. So it simulates realistic key presses, no way to tell the difference by any ways or means. – Hans Passant Apr 27 '12 at 00:19
  • DavidHeffernan i need to be able to remotely control the keyboard of one PC - from another (over LAN, to be more precise). All key-presses are going to be generated by software (C# WinForms), not the hardware (i.e. keyboard). Anyway, @HansPassant are you hundred percent sure about it? because if that's the truth - I suggest you to write this comment as an "answer" to my question. I'll gladly accept it. – Alex Apr 27 '12 at 07:01
  • @HansPassant - I'm certainly not an expert in this field, but after reading [this question](http://stackoverflow.com/q/5762007/402706), it would appear that your analysis may not be 100% true in all cases. – Brandon Boone Apr 27 '12 at 19:44
  • i did some homework and it seems like tools such as GameGuard can block SendInput() generated events, so basically, injections can be easily detected on a driver level. – Alex Apr 27 '12 at 21:32
  • So what options are available after all for impossible-to-detect key inputs? – user10478 Jul 22 '17 at 18:03
  • Off topic but... were you making a bot for some sort of game? :P – Tivie Sep 15 '18 at 02:00
  • @Tivie yes, for poker. Didn't succeed.. – Alex Sep 19 '18 at 11:00

1 Answers1

7

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().

Nejchy
  • 666
  • 11
  • 24