Printing Key Presses To The Screen Instantly With Python
Solution 1:
If it's ok to depends on the X window system, you can use the python-xlib module or the xpyb module to access the X window system and use a XGrabKey call to grab the keyboard related events. Upon each KeyPress
event you will be able to print the pressed key.
Now, if you really want to write a keymap, this is totally OS/window system dependent. If you use the X window system (Ubuntu does), you need to check the X documentation about how to write a new keymap. On Ubuntu, the current keymaps definition should be in /usr/share/X11/xkb
. Take a look, and try to copy and edit one. You can use setxkbmap
to change the current keymap then.
Solution 2:
To modify the key mapping of your keyboard, you must use the tools provided by your OS. Most applications don't accept generated events for security reasons.
In your case, that would be xmodmap
. Don't forget to create a backup of your current keymap using the -pke
option because you will make a mistake - and then, your keyboard won't be working anymore.
If you also want your new keymap work on the console, have a look at the kbd
package which changes the keyboard layout at the kernel level.
Post a Comment for "Printing Key Presses To The Screen Instantly With Python"