Generating a 'shifted' key (i.e. #)
Hi,
How would I determine what key codes to fire off to generate a specific character? (For instance to generate a '~' there is ecodes.KEY_GRAVE, but I don't see something like ecodes.COLON (for ':').)
So on my desktop I use a combination of KEY_LEFTSHIFT + KEY_SEMICOLON to generate a colon (:). How would I determine the correct sequence of events on a particular platform/keyboard layout?
Oh also this is using UInput.
Hello,
These things are determined by the kernel keyboard driver and the currently loaded translation table. Here is a good explanation on superuser.com: http://superuser.com/a/290149
For example, sudo dumpkeys -1 | grep -A5 colon | sed '/^$/Q gives you:
plain keycode 39 = semicolon
shift keycode 39 = colon
altgr keycode 39 = VoidSymbol
control keycode 39 = VoidSymbol
shift control keycode 39 = VoidSymbol
altgr control keycode 39 = VoidSymbol
alt keycode 39 = Meta_semicolon
shift alt keycode 39 = Meta_colon
control alt keycode 39 = VoidSymbol
I'm not aware of a python library that can do the parsing for you.
Best of luck, G.
Hi gvalkov,
Hmm, okay what would your advice be if dumpkeys doesn't work? (I get the error: Couldn't get a file descriptor referring to the console)
This is with Ubuntu Touch on a device (Nexus 4), this is my understanding on why it's not working.
The issue with dumpkeys: This appears to be due to there being no console/virtual terminal (i.e. neither CONFIG_VT_CONSOLE, CONFIG_VT_CONSOLE_SLEEP appear in /proc/config.gz). Neither is there a physical keyboard attached to the device so I presume that there is no keyboard driver loaded as expected?
So with me not being able to use dumpkeys does that complicate things? My understanding is that without the console dumpkeys cannot open the device and read the keyboard type via the KDGKBTYPE ioctl or KDGKBENT ioctl to get a keyboard mapping for a specific key/modifier.
And if this is true for dumpkeys, how does it effect python-evdev? I mean I know I can't grab the list of keycodes but how does it work the other way? (i.e. given keycodes -> python-evdev -> text on my screen). Does it all rest on the translation table? (i.e. I can't just take the keycodes that I use on my desktop, as I've already tried that).
Sorry for the long winded question, I'm wanting to solidify my understanding.
Regards, Chris
Hello and sorry for the late reply.
Android seems to be doing things differently. Here are a few documentation links that I found useful in understanding what's going on:
http://source.android.com/tech/input/keyboard-devices.html#keyboard-operation http://source.android.com/tech/input/key-layout-files.html http://source.android.com/tech/input/key-character-map-files.html
By parsing the key layout files, one should be able to map the evdev keycodes to their corresponding characters. I suppose there is a Java API for this, the implementation of which you can look into for more details.
Regards, G.
I have no idea if this works on Android, but I'm using unicode escape sequences (Ctrl-Shift-U-
Just in case it is useful to someone, someday: https://gist.github.com/paulo-raca/0e772864013b88de205a
(I know this is a very old issue but I have something to contribute)
You said
I'm not aware of a python library that can do the parsing for you.
It seems this exists now, in https://pypi.org/project/pynput/. It's built around python-evdev and their dumpkeys parser is here:
https://github.com/moses-palmer/pynput/blob/12acf84dc0f721d91a957da65311497acb664933/lib/pynput/keyboard/_uinput.py#L140