Qt 4.0: Character Input in Qt/Embedded

|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# Character Input in Qt/Embedded

Internally in the client/server protocol, each key press and key release is sent as a `QWSKeyEvent`. A QWSKeyEvent contains the following fields:

`unicode` | Unicode value
`keycode` | Qt keycode value as defined in `qnamespace.h`
`modifier` | A bitfield consisting of some of Qt::ShiftButton, Qt::ControlButton, and Qt::AltButton.
`is_press` | true if this is a key press, false if it is a key release.
`is_auto_repeat` | true if this event is caused by auto repeat.

When the server receives a key event it is sent to each client process which is responsible for processing the key event and sending it to the right window, if any. Key events may come from several different sources.

## Keyboard Drivers

A keyboard driver reads data from a device and gives key events to the server.

Keyboard drivers can be compiled into the library or loaded as plugins. Running ./configure -help lists the available keyboard drivers. The "tty" driver is enabled in the default configuration.

The keyboard drivers all follow the same pattern. They read keyboard data from a device, find out which keys were pressed, and then call the static function QWSServer::processKeyEvent() with the key information.

At present, the console keyboard driver also handles console switching (Ctrl+Alt+F1, ..., Ctrl+Alt+F10) and termination (Ctrl+Alt+Backspace).

To add a keyboard driver for a new device, subclasses of `QWSKeyboardHandler` and `QKbdDriverPlugin` can be written and installed as plugins.

If your keyboard supports either PC101 code set 1 scancodes, or the standard Linux keycodes, then you can save work by subclassing from QWSPC101KeyboardHandler rather than QWSKeyboardHandler.

For keyboards that support code set 1 scancodes, call QWSPC101KeyboardHandler::doKey() with the scancodes as keys are pressed.

For keyboards that support the standard Linux keycodes (see the Linux loadkeys manual page), compile with QT_QWS_USE_KEYCODES and call QWSPC101KeyboardHandler::doKey() with the keycodes as keys are pressed.

## Pen Input

Key events do not need to come from a keyboard device. The server process may call QWSServer::sendKeyEvent() at any time.

Typically, this is done by popping up a widget, and letting the user specify characters with the pointer device.

Note: The key input widget should not take focus, since the server would then just send the key events back to the input widget. One way to make sure that the input widget never takes focus is to set the Qt::Tool widget flag in the QWidget constructor.

The Qtopia environment contains various input widgets such as Handwriting Recognition and Virtual Keyboard.