Display an overlay while a hotkey is pressed

alfredapplescriptkeyboardshortcut

I have recently switched to a keyboard with a particular layout, and I'd like to setup a system-wide keyboard shortcut to display an image overlay on the screen while pressed. This image would be a reminder of the keyboard setup.

I've found a few apps that allow for displaying an overlay over the screen, but I'm looking for something that can be toggled on and off at the press of a key.

Best Answer

I ended up using Karabiner as suggested by CJK, with the following custom script which I placed under ~/.config/karabiner/assets/complex_modifications/custom.json. Just replace AppName with the name of your app and the "from" keybind to your preferred combination. The format is described here.

{
  "title": "Custom modifications",
  "rules": [
    {
      "description": "Toggle AppName visibility",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "f1",
            "modifiers": {
              "mandatory": ["shift", "control", "option", "command"]
            }
          },
          "to": [
            {
              "shell_command": "osascript -e 'tell application \"System Events\" to set visible of process \"AppName\" to true'"
            }
          ],
          "to_after_key_up": [
            {
              "shell_command": "osascript -e 'tell application \"System Events\" to set visible of process \"AppName\" to false'"
            }
          ]
        }
      ]
    }
  ]
}

Then, inside of Karabiner-Elements, in the "Complex Modifications" tab, click on the "Add rule" button, then enable your custom rule (in my case, the application I want to toggle is Helium).

Enabling the setting inside of Karabiner