hammerspoon icon indicating copy to clipboard operation
hammerspoon copied to clipboard

Allow empty 'key' in hs.hotkey.new(mods, key, ...)

Open hy2850 opened this issue 2 years ago • 1 comments

Hello. I would like to create a key mapping for 'esc' button being pushed twice.

I've first tried the below code, but got error that empty string is not allowed for the 'key' argument.

Code hs.hotkey.new({"escape", "escape"}, "", ...)

Error log

** Warning:hs.keycode: key '' not found in active keymap or ANSI-standard US keyboard layout
** ERROR : Invalid key:  - this may mean that the key requested does not exist in your keymap 
(particularly if you switch keyboard layouts frequently)

Putting each 'escape' in the `mods` and `key` only maps **single**, not twice, 'esc' button push.

hs.hotkey.new({"escape"}, "escape", ...)

How do I create a keymap that only takes 2 mods?

hy2850 avatar Aug 25 '22 03:08 hy2850

I'm not sure I entirely understand your question, however the mods parameter only supports:

  • "cmd", "command" or "⌘"
  • "ctrl", "control" or "⌃"
  • "alt", "option" or "⌥"
  • "shift" or "⇧"

As a result, this: hs.hotkey.new({"escape"}... ) is not valid.

If you want something to trigger if the ESCAPE key is pressed twice, you'd just need to add some logic that detects multiple keypresses within a certain time period using a hs.timer.

latenitefilms avatar Sep 17 '22 11:09 latenitefilms