To receive the serial data from an Arduino in Java, you'll need the RXTX library, which is available here: http://fizzed.com/oss/rxtx-for-java - Installing instructions are in the compressed zip file.

Normally, without a controller, you would have to use your keyboard and mouse to play. In Java, there is a class called "Robot" that is made to imitate keystrokes and mouse movement.

Java API for Robot class: https://docs.oracle.com/javase/7/docs/api/java/awt...

I added the Java source code with comments, but I'll write about it here too.

Firstly, we open the serial port with the name (if it is not COM3, change it to the arduino's port) and the data (9600 baud, parity, data and stop bits..). You can download the skeleton from here: http://playground.arduino.cc/Interfacing/Java

In the SerialEvent function you can access the buffered input (the line created in the loop in arduino) with the input.ReadLine() function call.

Then, I'll pass the string to the guitar function, in which I'll make the steps to create the keystrokes.

The string is split into an integer array, because it is easier to check the values in that. The indexing is the same as in the Arduino.

If the first element of the array is one, that means that the first fret button is pressed, and we have to imitate that somebody pressed the '1' key on the keyboard. That's why we have the robot.keyPress(KeyEvent.VK_1); call.

If it was pressed, but it is released now, we have to release the key as well with the function call: robot.keyRelease(KeyEvent.VK_1);

If the second fret button is pressed, we'll call the robot.keyPress for the key '2' and so on and so forth.

I had to make it for every fret button, escape, and star power, and the strumming up and down. For the frets, the keys '1' to '5' are pressed corresponding to the index of the fret on the neck. For the strumming the UP and DOWN arrows are pressed, for the escape, it presses escape, and for star power, the key 'S'.

When the whammy is triggered, it calls the whammy function, which creates a new thread moving the mouse on the X axis, because it can be set in the game to activate the whammy with the mouse. When it moves, it oscillates, so it's not only binary 1 or 0 for the whammy. With a new thread started, you can go on pressing other keys and strumming, there won't be any problem. And also if you trigger the whammy multiple times, multiple threads are started and the mouse goes back and forth. I think it is a nice solution for the problem.

The communication is started after sending a '1' to the Arduino in the main function at the bottom.

If you try it out, when you press the fret buttons, it's the same as when you press the corresponding keys on your keyboard.

Let's set it in the game!