Can I simulate button presses of buttons on a keyboard with the Java Robot class (Java.awt.robot)?

I use Arduino Uno to connect a (genuine) SNES controller to my computer via USB or Bluetooth.

Arduino captures controller buttons and releases using the snespad library . It conveys button presses and releases in the form of characters (for example, β€œa” for pressing A, β€œA” for releasing β€œA”). The Java program then listens for serial output using the rxtx library . Finally, the Java robot simulates keystrokes using keyPress and keyRelease .

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

There is no KeyEvents game panel in Java. When I say "KeyEvent game panel", I mean something like the Android SDK: http://developer.android.com/reference/android/view/KeyEvent.html (ctrl + f "game panel" or "button ".)

My question is, is there a way to simulate clicking a mouse button instead of keys using the Java robot class?

+6
source share
2 answers

USING THE ROBOT CLASS IN JAVA

You can create virtual keys / releases as follows ...

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); 

amuses

0
source

You should be able to easily from my experience, the gamepad buttons are displayed on the keyboard buttons, the only mapping I know is i, j, k, l going to look around and w, a, s, d go to move

0
source

Source: https://habr.com/ru/post/922494/


All Articles