hammerspoon icon indicating copy to clipboard operation
hammerspoon copied to clipboard

Hammerspoon sometimes doesn't pick up keys bound to a modal

Open Grazfather opened this issue 2 years ago • 17 comments

Sometimes hammerspoon will get into a state where I have a modal up, but it won't listen to any of the keys bound with the modal. When it's in this state, it happens consistently, as in I can re-create the modal and face the same issue. When I close the modal I see hotkey: Deleted hotkey ... for each key in the modal, suggesting it was actually bound.

Seems to persist restarting Hammerspoon at the moment.

Running version 0.9.97 on Monterey 12.6

Any suggestions on how to get extra info to debug when in this state?

Grazfather avatar Oct 28 '22 13:10 Grazfather

> xx = function() hs.alert("test") end
> xx()
> m = hs.hotkey.modal.new({}, nil)
> m:bind({}, "w", xx, nil, nil)
table: 0x600002834a40
> m:enter()
table: 0x600002834a40
-- I press 'w' a bunch here. No dice.
> m:bind({}, "W", xx, nil, nil)
table: 0x600002834a40
> m:exit()
table: 0x600002834a40
> m:delete()
2022-10-28 09:30:56: 09:30:56     hotkey: Deleted hotkey W
2022-10-28 09:30:56:              hotkey: Deleted hotkey W

Grazfather avatar Oct 28 '22 13:10 Grazfather

I noticed that they work fine if I add any mods, so it's only 'raw' key bindings that are the issue.

Grazfather avatar Oct 28 '22 14:10 Grazfather

just want to chime in that it has happened to me too in the same way (Monterey 12.2.1):

  • single chars with no modifiers broken, but not all of them, for me "Q" broke but "W" kept working
  • problem persisted after HS restart
  • I can't remember how the problem fixed itself but it was only broken for like half a day

Madd0g avatar Nov 12 '22 21:11 Madd0g

It's been broken for me for a few days this time.

Grazfather avatar Nov 16 '22 14:11 Grazfather

It never recovered. Bright side is that I can do a lot of testing. Bad side is that this makes hammerspoon just about useless to me. Would appreciate some suggestions on how to diagnose. If I change my bindings to use a mod they work, so it's only 'bare' hotkeys that are broken.

Grazfather avatar Dec 09 '22 13:12 Grazfather

I have the same problem on Montery 12.6.1 with an Apple M1 macbook.

Only noticed it when I uninstalled Karabiner Elements. However, when I reinstall Karabiner Elements, it's all working again, so this might be a workaround…

muhqu avatar Dec 15 '22 19:12 muhqu

I have also had this issue a few times. A workaround that has worked for me more than once is putting my computer to sleep and waking it back up.

valrus avatar Jan 03 '23 18:01 valrus

I was able to fix this by changing my karabiner elements settings, though unfortunately I don't know what I needed to change. Looking at a diff it seems that I had custom settings for specific hardware (e.g. builtin vs external), and once I removed that it started working again for both.

Grazfather avatar Jan 04 '23 14:01 Grazfather

just some side notes:

  • as i remember W and w are the same? you have to add a shift modifier?
  • maybe macOS default hotkeys are overwriting the settings?

muescha avatar Jan 11 '23 19:01 muescha

I have the same problem with hammerspoon 0.9.100. I'm also using Karabiner Elements. Only way to fix it I found so far is to log out and in again. Neither restarting hammerspoon nor Karabiner Elements helps. I don't know if its relevant, but I'm using spacehammer config

The modals are working after a fresh login and when they stop working I see the letters being send to to the window. So I don't think maxOS dfeault hotkeys or a missing shift modifier are the problem. Anything I can do to help finding the problem?

xabbu42 avatar Mar 19 '23 20:03 xabbu42

If something is stopping after some time: be sure that you hold a reference in a local variable so that the garbage collector not wipe it

muescha avatar Mar 19 '23 21:03 muescha

if it was a garbage collector problem, would restarting hammerspoon not fix it?

xabbu42 avatar Mar 19 '23 21:03 xabbu42

Yes. Then restarting HS would solve it.

muescha avatar Mar 19 '23 21:03 muescha

Has anyone found a fix for this?

I am on OSX Ventura and this is only fixed after logoff or restart of the mac, restarting hammerspoon does nothing. I am not using KE anymore since i only used it to swap FN and CTRL and this is supported by to OS now.

I am not sure how to debug this, could any one help.

My case is using WinMgr and when i enter modal mode, my commands with [ and ] work but with letter does not

moveAndResize = function(move)
	return function() 
		spoon.WinWin:moveAndResize(move)
		spoon.ModalMgr:deactivate({"resizeM"})
	end
end

cmodal:bind('', 'f', 'Fullscreen', moveAndResize("fullscreen")) -- stops working
cmodal:bind('', '[', 'Half Left', moveAndResize("halfleft")) -- working fine
cmodal:bind('', ']', 'Half Right', moveAndResize("halfright")) -- working fine

karamfil avatar Jun 09 '23 14:06 karamfil

This issue seems similar #3293

xvrdm avatar Sep 20 '23 14:09 xvrdm

Has anyone found a fix for this?

I am on OSX Ventura and this is only fixed after logoff or restart of the mac, restarting hammerspoon does nothing. I am not using KE anymore since i only used it to swap FN and CTRL and this is supported by to OS now.

I am not sure how to debug this, could any one help.

My case is using WinMgr and when i enter modal mode, my commands with [ and ] work but with letter does not

moveAndResize = function(move)
	return function() 
		spoon.WinWin:moveAndResize(move)
		spoon.ModalMgr:deactivate({"resizeM"})
	end
end

cmodal:bind('', 'f', 'Fullscreen', moveAndResize("fullscreen")) -- stops working
cmodal:bind('', '[', 'Half Left', moveAndResize("halfleft")) -- working fine
cmodal:bind('', ']', 'Half Right', moveAndResize("halfright")) -- working fine

I have the same issue on M1 MacBook with MacOS 13.2.1. It seems only [0-9a-Z] not working, other key binding still work.

And I noticed that keypress at [0-9a-Z], won't be captured by hammerspoon, but directly get into whatever running at foremost. for example: If I call modalMgr while using MacVim, and Press key "i" which binds to open iTerm, but now MacVim captures this key press, and enter insert mode.

wych42 avatar Oct 07 '23 06:10 wych42

the issue is no longer there for me, hammerspoon 0.9.100 (6815), karabiner-elements 14.13.0, macos Ventura 13.6.7

xabbu42 avatar Jun 22 '24 08:06 xabbu42