lejos.addon.keyboard
Class Keyboard

java.lang.Object
  extended by java.lang.Thread
      extended by lejos.addon.keyboard.Keyboard
All Implemented Interfaces:
Runnable

public class Keyboard
extends Thread

This class will only work with SPP keyboards, not standard HID keyboards. If it doesn't say it supports Bluetooth SPP then it will not work. There are currently only two known SPP models (also available on eBay or Amazon):

  • Freedom Universal Bluetooth keyboard
    http://www.freedominput.com
  • iTech Virtual Keyboard (SPP only)
    http://www.virtual-laser-keyboard.com/

    The SPP keyboards transmit keystrokes as one byte, not two like normal HID keyboards. For this reason, this class won't work properly with a regular HID keyboard as written. With modifications it could be made to work with both SPP and HID keyboards since the key tables are mostly the same.

    Note: This class is currently only tested with Freedom Universal. If you have problems with the iTech Virtual Keyboard, write to bbagnall@mts.net and I will try my best to adapt this class.

    Author:
    BB

    Field Summary
     
    Fields inherited from class java.lang.Thread
    MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
     
    Constructor Summary
    Keyboard()
              Makes Bluetooth connection to SPP keyboard.
    Keyboard(InputStream in, OutputStream out)
              Creates a new Keyboard instance using streams from the keyboard.
     
    Method Summary
     void addKeyListener(KeyListener kl)
              Starts a KeyListener listening for events from the keyboard.
     int getTypematicDelay()
              Typematic delay is the time after a key is held down that characters start repeating.
     double getTypematicRate()
              Typematic rate is the rate characters repeat when a key is held down.
     boolean isCapsLock()
              Indicates whether or not caps lock is enabled for the keyboard.
     void removeKeylistener(KeyListener kl)
              Removes the specified KeyListener from the Keyboard so it will no longer notify the listener of new events.
     void run()
              When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.
     void setTypematicDelay(int delay)
              Typematic delay is the time after a key is held down that characters start repeating.
     void setTypematicRate(int rate)
              Typematic rate is the rate characters repeat when a key is held down.
     
    Methods inherited from class java.lang.Thread
    currentThread, getName, getPriority, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, setDaemon, setName, setPriority, sleep, start, yield
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    Keyboard

    public Keyboard(InputStream in,
                    OutputStream out)
    Creates a new Keyboard instance using streams from the keyboard. Doesn't matter what the source is (Bluetooth, I2C, etc...)

    Parameters:
    in -
    out -

    Keyboard

    public Keyboard()
             throws BluetoothStateException
    Makes Bluetooth connection to SPP keyboard. The keyboard must have been paired already at the main menu. Will connect to the first paired SPP keyboard device that is turned on. NOTE: It can't distinguish between a GPS or Keyboard so make sure only the keyboard is on.

    Throws:
    BluetoothStateException - If it doesn't find an SPP device to connect to.
    Method Detail

    setTypematicDelay

    public void setTypematicDelay(int delay)
    Typematic delay is the time after a key is held down that characters start repeating.

    Parameters:
    delay - 250 ms to 1000 ms (500ms default)

    getTypematicDelay

    public int getTypematicDelay()
    Typematic delay is the time after a key is held down that characters start repeating.

    Returns:
    delay in milliseconds

    setTypematicRate

    public void setTypematicRate(int rate)
    Typematic rate is the rate characters repeat when a key is held down.

    Parameters:
    rate - 2.0 cps (characters per second) to 30.0 cps (10.9 default)

    getTypematicRate

    public double getTypematicRate()
    Typematic rate is the rate characters repeat when a key is held down.

    Returns:
    Rate in characters per second (cps)

    addKeyListener

    public void addKeyListener(KeyListener kl)
    Starts a KeyListener listening for events from the keyboard. Only one KeyListener is allowed.

    Parameters:
    kl -

    removeKeylistener

    public void removeKeylistener(KeyListener kl)
    Removes the specified KeyListener from the Keyboard so it will no longer notify the listener of new events.

    Parameters:
    kl -

    run

    public void run()
    Description copied from interface: Runnable
    When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

    Specified by:
    run in interface Runnable
    Overrides:
    run in class Thread

    isCapsLock

    public boolean isCapsLock()
    Indicates whether or not caps lock is enabled for the keyboard. The only way to change caps lock is to presss the Caps Lock key.

    Returns:
    true if caps lock is on, false if it is off.