How could I modify keystrokes programatically, per application?
peter.hutterer at who-t.net
Wed Sep 16 18:22:50 PDT 2009
On Wed, Sep 16, 2009 at 03:38:26PM -0400, James Ferguson wrote:
> I'm hoping for some pointers to get me on the right path... I am a
> developer who is unfamiliar with X development, but have a task in mind.
> I want to create an equivalent under X to the (Windows) XKeymacs app which
> makes emacs-style key bindings work almost universally, even for CUA-style
> applications (shift+movement to select, C-x to cut etc.). Ironically,
> XKeymacs makes XP nicer for those with deep emacs muscle-memory than X11 is.
> To do this I need to be able to:
> 1. Map or modify keystrokes depending on an internal state. e.g. if they
> enter Ctrl+n, then a down-arrow key would result; if the user has set a
> mark, then arrow-key movement needs a shift modifier added until a
> copy/cut/quit .
> 2. know what application is receiving the keystroke so the internal state
> for that application can be used.
> It seems that a naive approach with XGrabKeyboard and XNextEvent /
> XSendEvent won't work because many apps will not accept the events.
> Would I need to create a tweaked X Keyboard input driver, which monitors
> which window has focus? How would you approach it?
The XTest extension allows you to send keyboard and mouse events that look
like they come from a device. XTestFakeKeyEvent(4)
XGetInputFocus gives you the current focus window, with some querying of the
NET_WM_NAME you can probably find out which app it is.
More information about the xorg-devel