Hammerspoon: Up, Down, Left and Right keys do not repeat properly [Sierra, 0.9.52]

Created on 5 Apr 2017  路  5Comments  路  Source: Hammerspoon/hammerspoon

Related issues
Earlier issue: #1156
Possibly related #1179, #1178

Client
MacOS version: 10.12.3
Mac: MacBook Pro (13-inch, 2016, Two Thunderbolt 3 ports)

Software
hammerspoon 0.9.52

Description of issue
In #1156 I mistakenly thought the repeat key randomly stopping was for all keys, I am certain now that it is only for Up, Down, Left and Right[direction keys] keys.
At the very least, I am unable to reproduce it with any other key.

Use any of the methods below to test on Sierra and 0.9.52, try any key that is not a direction key, and it will repeat without issue.

Try to repeat on a direction key, and it will randomly stop after a seemingly random number of iterations.

One observable effect is that the random stop takes more repetitions to occur when you reload the hammerspoon config, but does still occur pretty much all the time.

.hammerspoon config

h = hs.hotkey.bind({}, "氓", function()
    hs.eventtap.event.newKeyEvent({}, "up", true):post()
end, function()
    hs.eventtap.event.newKeyEvent({}, "up", false):post()
end, function()
    hs.eventtap.event.newKeyEvent({}, "up", true):setProperty(hs.eventtap.event.properties.keyboardEventAutorepeat, 1):post()
end)
local function keyCode(key, modifiers)
    modifiers = modifiers or {}

    return function()
        -- Keydown event only firing due to sleep and keyup
        local event = require("hs.eventtap").event
        event.newKeyEvent(modifiers, key, true):post()
        hs.timer.usleep(100)
        event.newKeyEvent(modifiers, string.lower(key), false):post()
    end
end

hs.hotkey.bind({''}, '氓', keyCode('up'), nil, keyCode('up'))
bug help wanted

All 5 comments

Hey,

Unfortunately, after a bit of testing, I think this bug does happen even with characters, not just the arrow keys. I tried to change one of my standard arrow key mappings to "r", and after a few hours, it also stopped repeating after ~6 repeats.

It did take far longer for the bug to start than with the arrow keys, though.

This, btw, is a huge problem with Hammerspoon, and by far the biggest problem I have with it (probably the only problem, actually, but it's a serious issue for me). :(

@edanm yes, it makes any task that requires repeating keys rather difficult, I however only experience it with arrow keys on the supplied hardware and software

Recent newcomer to Hammerspoon after Karabiner stopped working when I upgraded to Sierra. This issue was a bit of a problem for me, as I'm a huge keyboard guy and want emacs keys everywhere. It may be slightly premature to declare victory, but I have what seems to be a working workaround for this, in the form of using a timer that starts on key down and stops on key up. Basically, I'm implementing my own key repeat.

Really crappy code can be seen here: https://github.com/candera/scripts/blob/master/hammerspoon/init.lua

It could definitely be done better, but I think the basic idea is outlined. A hack, but one that seems to work for me.

I would note that Karabiner Elements can now do complex remappings on Sierra, and may well be suitable for use here. If it is suitable, it would be a much more appropriate way to remap keys, than Hammerspoon :)

It's the "if suitable" that is the problem. While I find Karabiner Elements to be a stable solution, it is not as flexible as Hammerspoon, and I can't do everything with it that I used to be able to do with Karabiner.

Unfortunately, I find that Hammerspoon frequently "beachballs" for me when running my script, generally after an hour or two. Which is too bad - that approach works fine most of the time, and obviously has a lot of possibilities.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lazandrei19 picture lazandrei19  路  4Comments

dasmurphy picture dasmurphy  路  4Comments

luckman212 picture luckman212  路  4Comments

jasonrudolph picture jasonrudolph  路  4Comments

jiahut picture jiahut  路  3Comments