3

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 '16 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. – roaima Jul 27 '16 at 22:32
2

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.