PackageDescription: OS-Keyboard

OS - Keyboard

Last published: November 23, 2008 by 'mlucassmith'

Defines 3 Classes
Extends 6 Classes

This package provides an Immediate Mode OS interface to the current Keyboard state. It's a polling system where-by you update it with a snapshot of the current state. Changes to the state fire off events toggling between up and down state. This mechanism differs from the built in engine such that you will only get one signal per change - you will not be informed of keyboard repeat events while a key is held and regular keys will not send down/up combinations.

To use, instantiate a Keyboard for your platform with:
keyboard := Keyboard current.

You can then update the keyboard with the current state, eg:
keyboard update.

Now you can ask the keyboard for state information:
keyboard isDown: #LControl

You can also setup interest in state changes for keys, eg:
keyboard onDown: #LControl do: [Transcript cr; show: 'Left Control pressed'].
keyboard onUp: #LControl do: [Transcript cr; show: 'Left Control released'].
keyboard update.

This sort of keyboard interface, where you explicitly request an update, is not to be used in regular applications. This is more for engines that have a tightly controlled render loop - such as games.