On Windows, there's this tool AutoHotkey, it allows you to define application-specific hotkey for any application. I want to do the same thing on Linux: I have a global hotkey for language toggle (it's CapsLock, and it's defined in system settings), and I want to override this hotkey when in a certain application.

I'm on Ubuntu 14.04, under GNOME. I'm using xbindkeys to implement some global hotkeys.

  • 1
    Possible duplicate of Autohotkey Equivalent?
    – clk
    Jul 27, 2016 at 21:43
  • 1
    I don't think it's a duplicate because the other answer doesn't address the specific requirement of overriding the hotkeys application by application. Jul 27, 2016 at 22:32

1 Answer 1


Sufficiently advanced window managers (including Sawfish, Awesome, Fvwm, …) let you define per-window key bindings. Primitive window managers such as Metacity and Mutter (the Gnome defaults) don't. If you want to configure your window environment to do what you want rather than stick to some basic defaults, I recommend using a more advanced window manager. You can still use Gnome with many window managers including Sawfish and Fvwm.

If you want to set up key bindings independently of the window manager, you can use a program just for that, such as xbindkeys. Make your key binding invoke a shell script that acts differently based on the active window. You can use xdotool to retrieve the active window ID (also its title) and then other tools such as xprop to obtain more information about the window.

wid="$(xdotool getactivewindow)"
class="$(xprop -id "$wid" '$1' WM_CLASS)"; class="${class#*\"}"; class="${class%\"}"
case "$class" in
  Myapp) do something;;
  *) do something else;;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .