2

I bought a physical button and hooked it up to my computer, using the Arduino it communicates over USB serial to a C++ program I'm writing. Now I want to make the button simulate a keypress on my computer so I could use it as an alternative controller for the games I play.

If you are not familiar with Arduino, don't mind it, my problem lies completely in C++

The solution for this is pretty simple, it basically boils down to using SendMessage to a window with keystrokes, or many alternative methods like sendKeys and what not.

I have tried every single library or windows function that could handle something like this, but none of them actually simulates a keystroke being pressed by a keyboard.

Everything I tried so far has worked in many programs like Notepad and Chrome but none works with a game that doesn't listen to windows messages to handle key input.

My guess is that these games use GetAsyncKeyState which is communicating with the physical keyboard in a direct manner.

How could I resolve this? What API provides such functionality?

I need something very low level here, maybe even a program that emulates a new keyboard so windows thinks I have plugged in a physical one.

This would help me ALOT I've encountered this problem numerous times and I will keep encountering it in the near future with other projects.

I hope someone can help, Thanks!

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
user1091566
  • 121
  • 2
  • 10
  • [SendInput()](http://msdn.microsoft.com/en-us/library/ms646310%28v=vs.85%29.aspx)? – Alexey Frunze Mar 28 '13 at 17:09
  • 1
    Why not to implement USB HID keyboard-like device? IIRC, USB serial and USB HID may co-exist and work simultaneously. – hate-engine Mar 28 '13 at 17:29
  • I'd rather keep it software based for low cost reasons, but I might go for that if this is impossible – user1091566 Mar 28 '13 at 21:52
  • I have successfully implemented such a USB software only solution using V-USB : http://www.obdev.at/products/vusb/index.html – HBP Mar 29 '13 at 18:24

1 Answers1

0

Use keybd_event() or SendInput()

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I tried both and they don't work. I run Audiosurf (or almost any other full screen game) and run this code: http://pastebin.com/aEcpHYMW When I press Left in the game I go to the left, but the code isn't doing anything. But it does work with all other programs that are currently running, like Chrome. – user1091566 Mar 28 '13 at 17:49