However, I'd like it to work with a game so that I can control one action with a foot switch. It doesn't do what I want it to do, with occasional random inputs being seen in the game.
I still need to use the keyboard and mouse as well.
However, I'd like it to work with a game so that I can control one action with a foot switch. It doesn't do what I want it to do, with occasional random inputs being seen in the game.
Did you use the same code to test the game? Does react the game to a "1" input?
Any ideas where I'm going wrong ?
No, the information you supplied isn't sufficient.
There's not a lot of information to go on but I suspect the the game will need the control to be held down, and Keyboard.print() doesn't do that - It sends a 'press' event and then immediately follows that with a 'release'
Have a look at using Keyboard.press() and Keyboard.release() instead.
Pseudo-code might be something like:
loop() {
Check the physical state of the control (pressed/released)
If the state now is different to the last time around then send press or release as required
Record the new state
}
So the problem is in your computer and not in the Arduino. It acts as a USB keyboard and sends a keycode for the 1 key (on standard keyboards, note not the 1 from the numeric block!) to the computer. If your game doesn't react to that it probably expects something else. We don't know what it expects.
I had similar problems with my own project. The timing of the keypress seems to be important - not too short or too long.
Otherwise the character can get ignored or misinterpreted.
Also try adding a delay after Keyboard.begin();