返回介绍

Character input in Qt/Embedded

发布于 2019-10-04 14:57:54 字数 3879 浏览 952 评论 0 收藏 0

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 are currently compiled into the library.
They are defined in the file src/kernel/qkeyboard_qws.cpp.
At the time of writing, the following drivers are defined:

QWSTtyKeyboardHandler

Input from the system console (tty)

QWSVr41xxButtonsHandler

Input handler for the buttons on Cassiopeia-style PDAs

QWSVFbKeyboardHandler

Virtual framebuffer key input

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, make a subclass of
QWSKeyboardHandler and instantiate it in
QWSServer::newKeyboardHandler() (in qkeyboard_qws.cpp).

Key event filters (input methods)

When the server receives a key event from a keyboard driver, it first
passes it through a filter.

This can be used to implement input methods, providing input of
characters that are not on the keyboard.

To make an input method, subclass QWSServer::KeyboardFilter (in src/kernel/qwindowsystem_qws.h) and implement the virtual function filter(). If filter() returns FALSE, the event will be sent to
the clients (using QWSServer::sendKeyEvent()). If filter() returns
TRUE, the event will be stopped. To generate new key events, use
QWSServer::sendKeyEvent(). (Do not use processKeyEvent(), since this
will lead to infinite recursion.)

To install a keyboard event filter, use
QWSServer::setKeyboardFilter(). Currently, only one filter
can be installed at a time.

Filtering must be done in the server process.

The launcher example contains an example of a simple input method,
SimpleIM which reads a substitution table from a file.

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 WStyle_Customize and WStyle_Tool widget flags in
the QWidget constructor.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文