de.jreality.toolsystem.raw
Class DeviceKeyboard

java.lang.Object
  extended by de.jreality.toolsystem.raw.DeviceKeyboard
All Implemented Interfaces:
PollingDevice, RawDevice, AWTEventListener, KeyListener, EventListener

public class DeviceKeyboard
extends Object
implements RawDevice, KeyListener, AWTEventListener, PollingDevice

This driver mainly consists of a workaround for the keyboard auto-repeat: Windows: The auto-repeat on windows triggers repeating key-pressed events, and also key-typed events which we ignore. So the only thing to do is to check the last state of the key and only handle a key-pressed if the key was not pressed before. This happens in poll(). Linux: The auto-repeat on linux triggers repeating key-released/key-pressed events, so we enqueue the occuring events and merge them if possible: When a key-released event occurs, we check if there is a matching key-pressed event in the queue - if yes ignore both events. Happens in handleEvent(..). MacOS: Seems to work! Solaris etc.: TODO! Now this class also listens to mouse events and always checks if the status of shift/ctrl/alt/algt_graph/meta has changed without a corresponding event.

Author:
Steffen Weissmann

Constructor Summary
DeviceKeyboard()
           
 
Method Summary
 void dispose()
           
 void eventDispatched(AWTEvent event)
           
 String getName()
           
 void initialize(Viewer viewer)
           
 void keyPressed(KeyEvent e)
           
 void keyReleased(KeyEvent e)
           
 void keyTyped(KeyEvent e)
           
 ToolEvent mapRawDevice(String rawDeviceName, InputSlot inputDevice)
           
 void poll()
          Perform polling for the device in this method.
 void setEventQueue(ToolEventQueue queue)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DeviceKeyboard

public DeviceKeyboard()
Method Detail

initialize

public void initialize(Viewer viewer)
Specified by:
initialize in interface RawDevice

keyPressed

public void keyPressed(KeyEvent e)
Specified by:
keyPressed in interface KeyListener

keyReleased

public void keyReleased(KeyEvent e)
Specified by:
keyReleased in interface KeyListener

keyTyped

public void keyTyped(KeyEvent e)
Specified by:
keyTyped in interface KeyListener

mapRawDevice

public ToolEvent mapRawDevice(String rawDeviceName,
                              InputSlot inputDevice)
Specified by:
mapRawDevice in interface RawDevice
Returns:
a ToolEvent representing a reasonable initial value for the mapping - that means the source must be the given input slot!

setEventQueue

public void setEventQueue(ToolEventQueue queue)
Specified by:
setEventQueue in interface RawDevice

dispose

public void dispose()
Specified by:
dispose in interface RawDevice

getName

public String getName()
Specified by:
getName in interface RawDevice

toString

public String toString()
Overrides:
toString in class Object

poll

public void poll()
Description copied from interface: PollingDevice
Perform polling for the device in this method.

Specified by:
poll in interface PollingDevice

eventDispatched

public void eventDispatched(AWTEvent event)
Specified by:
eventDispatched in interface AWTEventListener