Hammerspoon / hammerspoon

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

Is there a way to do keywait? #1954

Closed ericwu17 closed 6 years ago

ericwu17 commented 6 years ago

In autohotkey, it is possible to do keywait, which waits for a certain key to be pressed. Is there a way to do this in hammerspoon? I am trying to recreate the hotstrings function of AHK.

Thanks, Eric

latenitefilms commented 6 years ago

You can use hs.eventtap.event to watch for keypresses. You could use hs.timer.doAfter to remove the observer after a certain period of time.

cmsj commented 6 years ago

I'm not really familiar with autohotkey, could you describe a bit more detail about the exact sequence you're looking for?

ericwu17 commented 6 years ago

@cmsj , I want hammerspoon to excecute something after I press some keys in succession, such as when I press D then A then T then E, hammerspoon will press the delete key 4 times and then fill out the current date.

cmsj commented 6 years ago

Aha, thanks. So, that is possible using hs.eventtap, but it's not going to be easy or pretty. Honestly for that specific use-case I think you'd be better off with something like TextExpander. Sorry!

ericwu17 commented 6 years ago

So mor specifically, how would it be done? A single hs.eventtap to watch for the D key, and then how would it detect teh A key being pressed?

cmsj commented 6 years ago

You’d create one event tap and listen for all key presses, and keep track of the most recent X number of presses. If the most recent presses match DATE or some other string, fire off some kind of function call to do what you want.