Skip to content
Advertisement

Generate combined virtual key presses to get chars like â, ó, ć, and more complex

I’m implementing a virtual keyboard using QML.

So far I literally map the char to print for the different key maps (w/o shift, with shift, with Alt Gr, etc.).

So I have to write down all the chars for different layouts somewhere in the code.

Especially for layouts and languages where two or more key presses generate a more complex char like pressing ` followed by a to get à becomes very nasty.

So I think this is a sub-optimal approach and there is a much cleverer solution to just provide the scan codes (as provided by ‘showkey -s’ in Linux) and to use the systems locale settings to get the correct char printed in let’s say a QQuick LineEdit.

What would be the best/correct way tho pass the scan codes to the system to generate “real” key events and how could I “receive” them in my code.

System is Linux. C++ backend would by fine. Guess QML alone won’t be capable … May It be clever to generate an own keyboard input device for this ?

Or could I inject the scan codes into the existing keyboard device to simulate the presses ?

Advertisement

Answer

Following code derived from

How to Generate Keyboard Input Using libevdev in C

using libevdev seems to point into the right direction.

It allows to send scan codes to a newly created keyboard device (needs root).

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement