2
votes

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!

1
Why not to implement USB HID keyboard-like device? IIRC, USB serial and USB HID may co-exist and work simultaneously.hate-engine
I'd rather keep it software based for low cost reasons, but I might go for that if this is impossibleuser1091566
I have successfully implemented such a USB software only solution using V-USB : obdev.at/products/vusb/index.htmlHBP

1 Answers