I'm aware of a number of ways of remapping key combinations in Ubuntu on a global basis (e.g., globally remapping Ctrl+S to send Ctrl+D or something), such as the xbindkeys application. What I need, though, is a way to do this only for a specific application. For example, something like "Remap Ctrl+S to send Ctrl+D, but only in Chrome". Is there any way to accomplish this?
Your idea of using xbindkeys sounds good:
This will execute
Now you need to define the script. It should get the active window and from that the name of the app which currently has the focus:
This would do the trick: it asks xdotool for the active window, then asks xprop for all properties of the window with the given id, and then reduces the very verbose output to the name of the application (actually its class). If you run this in a gnome-terminal you would get
Now you need to define actions for your applications:
So together, the script
This should work, but as in this question, I have to admit that it does not. Probably because one of Compiz, Unity, Global Menu does not work well with the
As a sidenote: this will not work, if you want to change keys for programs which run in a terminal (e.g. vi or emacs in console mode). The returned application class would still be "Gnome-terminal".
Hope that helps.
autokey is like AutoHotkey for Ubuntu. You can write scripts in python and have them execute via keyboard shortcut and a windows filter (making it pseudo-application specific). Your script can control keyboard and mouse events and even move windows around as an added touch.