January 10, 2014

Qt, embedded Linux, Keyboard map

If you happen to use Qt for your embedded Linux project, and need keyboard support. The following things may be useful.

1. Qt supports keyboard keymap since version 4.6. By default it uses the default keymap,  which has a bug (unfixed as of early 2014) that prevents CAPS LOCK and num lock to work. See details here: https://bugreports.qt-project.org/browse/QTBUG-9843 . You can either patch it using the patch file on that bug report , or use an external keymap file.

2. To use an external keymap file, you need to obtain the Linux keymap file package (http://lct.sourceforge.net/data.html click on "Download" on the left),  untar it, get "keymaps/i386/qwerty/us-latin1.kmap". This file is for the default US keyboard. Use the keymap that matches your keyboard.

3. Qt includes a tool named "kmap2qmap" to convert the above kmap file to a qmap file that Qt applications can uses. You may want to patch the "kmap2qmap" source code to prevent this bug. It's a simple patch. Then run it as "kmap2qmap us-latin1.kmap us.qmap", and you should get the new file "us.qmap". It is safe to ignore the warnings.

4. Put this qmap file in your system, let's assume "/opt/us.qmap", and set the following env variable:
export QWS_KEYBOARD="<driver>:keymap=/opt/us.qmap".  I use a qt keyboard driver plugin in my setup so I don't use the variable, but this is supposed to be how your run it. More details here.

That's it. Now your new keyboard should work. :-) I know, finally!

P.S. this website (and this one) provides good information on keyboard scan code (Set 1, Set 2, Set 3, USB HID, etc)

1 comment:

  1. Hello there,
    I have an embedded Qt application crosscompiled that runs on BeagleBone Black. It works Ok, but one thing- It doesnt accept keyboard input if i wont run in directly on BeagleBone Black preceeding with sudo. This is a problem because:

    I cannot remote debug application and use connected keyboard, as it doesnt work,
    I cannot use keyboard when the app is in rc.local file to boot at startup (even though sudo is used there).

    This is critical for me at the moment and I cannot find solution to the problem for very long. I would really apreciate all help regarding this.

    My /etc/enviroment content is here:

    QWS_MOUSE_PROTO=IntelliMouse:/dev/input/mouse0
    QWS_KEYBOARD=LinuxInput:/dev/tty
    TSLIB_CONFFILE=/etc/ts.conf
    TSLIB_PLUGINDIR=/usr/lib/ts

    Although I have tried many different configurations for QWS_KEYBOARD. The keyboard I would like to use is /dev/input/event1.

    Here are my persmissions: My application rights are:

    -rwxrwxrwx 1 root root 353100 Mar 2 2015 OvenViewer

    And the input device rights are:

    crwxrwxrwt 1 root root 13, 65 Mar 1 21:45 event1

    I have set the rights in a file /etc/udev/rules.d/85-pure-data.rules:

    KERNEL=="event1", MODE="777"

    Do you know maybe what could be the case? I would really apreciate help...

    ReplyDelete