Skip to content

Checking if Devices were removed or added

Ralph Niemitz edited this page Mar 30, 2018 · 2 revisions

In the DeviceListener class is the default method onRemove. It is called when the device was removed. When a device is removed it will automatically be removed from the device list in the DeviceManager. If a device is connected it will automatically be added to the list.

WARNING! This is not guaranteed to work and highly depends on the JInput plugin implementation with wich the device list is created!

Example Code

public class Adapter extends KeyboardAdapter {

	@Override
	public void onKeyPress(KeyboardEvent event) {
	
		System.out.println("====");
		System.out.println("Code: " + event.getKeyCode());
		System.out.println("Name: " + event.getKeyName());
		System.out.println("====");
	}
	
	@Override
	public void onRemove() {
	
		System.out.println("The keyboard was removed");
	}
}