Ask questionsAdd ability for hs.eventtap to use the global queue

If I trigger the below code in the console:

hs.eventtap.event.newKeyEvent(, true):post()

...I expect it to hold down the SHIFT key until I trigger:

hs.eventtap.event.newKeyEvent(, false):post()

...however it doesn't seem to do anything?

I've also tried hs.eventtap.event.newKeyEvent({},, true):post().

Any ideas?


Answer questions asmagill

The event "queue" that hs.eventtap.event uses is not the global one, but rather one unique to Hammerspoon (I remember trying the global one at one point and it broke some things people were used to so didn't really pursue it further, though when I was working on an eventtap replacement (which might be worth reconsidering for 2.0) I did make this a choice you could set when creating the event).

Because of this, the "shift" key isn't "pressed" globally (i.e. events originating outside of Hammerspoon do not see this flag as having been set)

As an example, try the following in the console:

t = true ; d = hs.hotkey.bind({"cmd","alt"}, "S", nil, function() hs.eventtap.event.newKeyEvent(, t):post() ; t = not t ; end)

Now, press and release Cmd-Alt-S. Type something into the console (without the shift key pressed) and you'll see it in lower case, BUT try this in the console:

hs.eventtap.event.newKeyEvent(, true):post() ; hs.eventtap.event.newKeyEvent(, false):post()

And you'll see an upper case A appear in the console's input field.

To verify it's because of our hotkey, press and relase Cmd-Alt-S again, and then repeat the sample posts... this time, the input field receives a lower case a.

Github User Rank List