Can I simulate game pad button presses with Java's Robot class (Java.awt.robot)?
Asked Answered
M

2

6

I'm using an Arduino Uno to hook a (genuine) SNES controller to a computer via USB or Bluetooth.

The Arduino captures the controller's button presses and releases using the snespad library. It communicates button presses and releases as characters (e.g. 'a' for pressing A, 'A' for releasing 'A'). Next, a Java program listens to the serial output using the rxtx library. Finally, a Java robot simulates key presses using the keyPress and keyRelease.

Unfortunately, this approach has a few drawbacks. The main issue is key mapping. I kind of arbitrarily decided which buttons would be which keyboard keys.

Java doesn't appear to have any game pad KeyEvents. When I say "game pad KeyEvent," I mean something like what the Android SDK has: http://developer.android.com/reference/android/view/KeyEvent.html (ctrl+f "game pad" or "button".)

My question is, is there a way to simulate game pad button presses instead of keystrokes using Java's robot class?

Mastoid answered 9/8, 2012 at 18:46 Comment(2)
Is there a reason you can't just press control and 'f' using the Robot?Lighterage
Sorry. I was saying if you search for "game pad" or "button" on that web page, you'll find the buttons included the Android SDK.Mastoid
R
0

USING THE ROBOT CLASS IN JAVA

You can create virtual keypresses/releases in the following way...

Robot robo=new Robot();
robo.keyPress(KeyEvent.VK_A);
//don't forget to release it else you'll land up in infinite loop
robo.KeyRelease(KeyEvent.VK_A);

cheers

Righteous answered 17/4, 2013 at 8:37 Comment(0)
G
-1

You should be able to easily from my expierience the gamepad buttons are mapped to keyboard buttons the only mapping i know it i,j,k,l go to looking around and w,a,s,d go to moving around

Glassine answered 28/8, 2016 at 22:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.