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!

marked as duplicate by Chris Stratton, Mattia, jfpoilpret, Nick Gammon Aug 1 '16 at 5:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • We already have a question on this very topic, we really don't need to cover it again. – Chris Stratton Jul 27 '16 at 1:37
3

Not without extra software on your computer side.

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

  • 2
    Or you could change the firmware on the ATMega16u2 on the UNO. But that isn't for the faint of heart. – Gerben Jul 25 '16 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) – KIIV Jul 25 '16 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

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);  
  • 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. – John Burger Jul 26 '16 at 11:00
  • @JohnBurger sorry, you are right! my mistake.... – Leah Jul 26 '16 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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.