Reputation:
I'm writing a macro generator/ keyboard remapper in python, for xubuntu.
I've figured out how to intercept and record keystrokes, and send keystrokes I want to record, but I haven't figured out how to block keystrokes. I need to disable keyboard input to remap a key. For example, if I wanted to send 'a' when I press the 's' key, I can currently record the 'a' keystroke, and set it to playback when I press the 's' key. I cannot, however keep the 's' keystroke from being sent alongside it.
I used the pyxhook module from an open source keyboard-logger for the hooks, and a again, the xtest fake input method from the python x library.
I remember reading somewhere about somebody blocking all keyboard input by redirecting all keystrokes to an invisible window by using tkinter. If somebody could post that method that'd be great.
I need something that will block all keystrokes, but not turn off my keyboard hooks.
Upvotes: 5
Views: 5411
Reputation:
I've got a keyboard hook that detects X events. I'm looking for a way to globally prevent a single keyboard event from being sent to a window. Something that works by accessing the event queue and removing the keyboard event from it would be ideal. It looks like it should be possible using Python Xlib, but I can't figure it out.
Upvotes: 0
Reputation: 788
I think it's going to depend heavily on the environment: curses & the activestate recipe are good for command line, but if you want it to run in a DE, you'll need some hooks to that DE. You might look at Qt or GTK bindings for python, or there's a python-xlib library that might let you tie right into the X system.
So I guess the answer is "it depends." Are you looking for console noecho functionality, or a text replacement program for a DE, or an xmodmap-style layout changer?
Upvotes: 1