Hammerspoon / hammerspoon

Staggeringly powerful macOS desktop automation with Lua
http://www.hammerspoon.org
MIT License
12.12k stars 582 forks source link

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

Open hy2850 opened 2 years ago

hy2850 commented 2 years ago

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?

latenitefilms commented 2 years ago

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

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.