Just recently, I came across a dilemna why one of our pedal devices would not work with our Java program. We already incorporated the code to communicate with it by using key listeners and mapping key codes with the pedal.

Turns out that the pedal device was detected as a gamepad device. Luckily, there is an existing Java library to handle gaming device communication. I used JXInput and it worked flawlessly. Plus, the code is easy to write too.

JXInput gives access to any number of DirectInput gaming devices – although it seems to be quite unusual to have more than one connected. Additionally, JXInput allows to interpret each key on the keyboard as interpreted by Swing to be a JXInput button. This gives another source for about 100 additional buttons.

Here is a simple class I made to initialize the gamepad device to be usable in your Java program.

It is up to you to change the key code values with which you want to associate the pedal/button values. To use the class, simply instantiate it and set the Component that it should listen to whenever you step on the pedal.

To use the class, do this:

Where comp is your component UI that handles pedal functions in case users do not have any pedal device.

Interfacing a foot pedal device using Java may look hard at first unless you have an idea which event in Java you need to interface it with. Luckily, my friend Junald already was able to sort out the logic behind making the foot pedal work with Java. And it all lay upon the keyboard events.

The foot pedal model I used is the Infinity IN-USB-1 Foot Pedal. It is a 7.5″ x 5.5″ x 1.5″ USB device that can be used to provide input to your PC using the foot. You can press the left, center or right pedals (or any combination of them) to provide input to your PC.

I have provided 3 source files:

FootPedalManager.java – instantiate the class to be able to make your foot pedal device work with your program

FootPedalDispatcher.java – links keyboard events with the foot pedal device

MyClass.java – this is your custom made user interface class where it contains buttons like rewind, forward and play/stop. I will not place the complete code in this class but only part of it that links the keyboard events to the buttons.

Related Posts Plugin for WordPress, Blogger...