Input in ClanLib is accessed via a clan::InputContext object, which is usually acquired from a clan::DisplayWindow object. The input context interface is a container holding one or more clan::InputDevice objects, each acting as either a keyboard, mouse, joystick or tablet source. The input device interface provides access to various polling functions or signal callbacks, which are invoked when ClanLib receives these input messages.
The following example shows how to get the input devices for the first keyboard, mouse and joystick:
Polling a device is fairly simple and straight forward (just call the appropriate functions), but the actual state of an input device does not always update immediately - in some cases they are updated based on input messages received from the underlying windowing system, which means that they will not update until you have made a call to clan::KeepAlive::process(). The following code correctly polls for hitting escape to quit the loop:
An alternative to polling input devices is to set up callback functions that get invoked whenever an input event occurs. To do this, simply connect a slot function to the signal you want to listen in on: