profile
viewpoint

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

If I trigger the below code in the console:

hs.eventtap.event.newKeyEvent(hs.keycodes.map.shift, true):post()

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

hs.eventtap.event.newKeyEvent(hs.keycodes.map.shift, false):post()

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

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

Any ideas?

Hammerspoon/hammerspoon

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(hs.keycodes.map.shift, 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(hs.keycodes.map.a, true):post() ; hs.eventtap.event.newKeyEvent(hs.keycodes.map.a, 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.

useful!
source:https://uonfu.com/
Github User Rank List