0

I looked up the question before, but they only gave answers for boards that are not the Uno. Is there any way to make it so when I press a button on my board, it registers as a key press on my computer? I'm trying to make a flight controller for PC sims.

Thanks!

asked Jul 25, 2016 at 18:06
1
  • We already have a question on this very topic, we really don't need to cover it again. Commented Jul 27, 2016 at 1:37

4 Answers 4

3

Not without extra software on your computer side.

However if you use Arduino Micro, you can emulate keyboard and/or mouse directly.

answered Jul 25, 2016 at 19:13
2
  • 2
    Or you could change the firmware on the ATMega16u2 on the UNO. But that isn't for the faint of heart. Commented Jul 25, 2016 at 20:00
  • Yes, it came to my mind too, but FT232 or CH340 can be used in some cases (mainly if it's clone) Commented Jul 25, 2016 at 20:06
0

You'll need something on the Arduino that sends an event to your PC whenever the button is pressed. The easiest version of this would be the Serial channel over USB.

Second, you'll need a program running on your PC that receives that Serial message and generates your desired keyboard and mouse events.

In Windows, you can generate system wide keyboard and mouse events fairly easily using the Windows API. This would allow you to click a mouse, or keyboard button when inside of most programs written in Windows. https://msdn.microsoft.com/en-us/library/ms171548(v=vs.110).aspx

That said, you can have problems sending spoofed events to video games that don't use standard Windows forms. You might find this answer helpful from StackOverflow - https://stackoverflow.com/questions/7320424/c-win32-simulate-keypress-with-directinput

answered Jul 25, 2016 at 23:48
0

EDIT: check @JohnBurger 's comment. THIS is NOT good for the UNO.

You can connect your Arduino as a keyboard to the computer. There is a Keyboard Arduino library you can use. Here is a reference: KeyboardWrite

For example this line of code will react just like you pressed A on your keyboard:

Keyboard.write(65); 
answered Jul 26, 2016 at 10:51
2
  • Note the first line of the parent Keyboard [arduino.cc/en/Reference/MouseKeyboard] reference page: "These core libraries allow a 32u4 based boards or Due and Zero board to appear as a native Mouse and/or Keyboard to a connected computer" - in other words, not the Uno that the questioner was asking about. Commented Jul 26, 2016 at 11:00
  • @JohnBurger sorry, you are right! my mistake.... Commented Jul 26, 2016 at 11:17
0

You can do USB HID device on any AVR or Arduino chip without USB hardware interface by bitbanging on any 2 DIO:

https://www.obdev.at/products/vusb/index.html

Supports 4 endpoints (削除) (like 2 mouse and 2 keyboard, if makes sense :) (削除ここまで). Sure no additional software or driver is needed on OS side (default drivers shall be ok if correct VID/PID specified).

EDIT:

Seems 2 endpoints are required for USB HID keyboard. If remaining 2 is enough for USB HID joystick, it could be useful for flight sim.

answered Jul 26, 2016 at 17:49

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.