Package event

Class MultiKeyListener

All Implemented Interfaces:
Configuration, KeyListener, EventListener

public class MultiKeyListener extends KeyAdapter implements Configuration
This class maintains a synchronized set of active keys. The KeyEvent.keyCode corresponding to the depressed key is added to the set when keyPressed is invoked, and removed from the set when keyReleased is invoked. When polled (getActiveKeys() is invoked), an array of the key codes of all depressed keys is returned.
Author:
Krish Pillai
See Also:
  • Constructor Details

    • MultiKeyListener

      public MultiKeyListener()
  • Method Details

    • keyPressed

      public void keyPressed(KeyEvent e)
      Specified by:
      keyPressed in interface KeyListener
      Overrides:
      keyPressed in class KeyAdapter
    • keyReleased

      public void keyReleased(KeyEvent e)
      Specified by:
      keyReleased in interface KeyListener
      Overrides:
      keyReleased in class KeyAdapter
    • getActiveKeys

      public int[] getActiveKeys()
      Returns the list of depressed key events or keyCode 0 if no key is pressed
      Returns:
      list The keys currently down
      See Also:
    • isEnabled

      public boolean isEnabled()
      Returns the state of this listener. If disabled, the listener returns a zero for the active keys.
      Returns:
      state The active state of the listener
      See Also:
    • enable

      public void enable()
      Sets the listener to enabled mode so it can save and retrieve key status.
    • disable

      public void disable()
      Sets the listener to disabled status. Key status will be set to all zeros.
    • reset

      public void reset()
      Clears out contents of active key tracking set.