Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generating a 'shifted' key (i.e. #) #7

Veebers opened this issue May 21, 2013 · 4 comments


Copy link

@Veebers Veebers commented May 21, 2013


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.


This comment has been minimized.

Copy link

@gvalkov gvalkov commented May 21, 2013


These things are determined by the kernel keyboard driver and the currently loaded translation table. Here is a good explanation on

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,


This comment has been minimized.

Copy link

@Veebers Veebers commented Jun 11, 2013

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.



This comment has been minimized.

Copy link

@gvalkov gvalkov commented Jul 1, 2013

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:

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.



This comment has been minimized.

Copy link

@paulo-raca paulo-raca commented Feb 12, 2016

I have no idea if this works on Android, but I'm using unicode escape sequences (Ctrl-Shift-U-) to write characters and it seems to work pretty well
(At least on applications based on Gnome -- it doesn't work on KDE and others)

Just in case it is useful to someone, someday:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.