Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to show what a keycode being pressed is? #2937

Open
vaterp opened this issue Aug 23, 2021 · 1 comment
Open

Is it possible to show what a keycode being pressed is? #2937

vaterp opened this issue Aug 23, 2021 · 1 comment

Comments

@vaterp
Copy link

vaterp commented Aug 23, 2021

More specifically I have a MS ERGO keyboard on a mac and I want to try and use hammerspoon to make some of the special keys work in the top row (the 1,2,3,4,5, calc, home, mail buttons).

My problem is that I dont know how to figure out what thier keycode names would be and if its even possible?

Thanks.

@jparoz
Copy link
Contributor

jparoz commented Sep 29, 2021

One approach that I take when trying to trigger things that I'm not sure are captured by Hammerspoon is to do something like this snippet:

hs.eventtap.new({hs.eventtap.event.types.keyDown, hs.eventtap.event.types.systemDefined}, function(event)
    local type = event:getType()
    if type == hs.eventtap.event.types.keyDown then
        print(hs.keycodes.map[event:getKeyCode()])
    elseif type == hs.eventtap.event.types.systemDefined then
        local t = event:systemKey()
        if t.down then
            print("System key: " .. t.key)
        end
    end
end):start()

This will print the keycode of any keyboard key pressed. If pressing the key you'd like to map causes its name to be printed in the console, then you know you can take actions when the key is pressed; the only step remaining is to modify the snippet to test which key is being pressed, instead of always printing its name.

The documentation for hs.eventtap.event:systemKey() might be helpful to you. I suspect that in your particular case of calculator and mail type keys, those keys might use a different USB device descriptor than standard keyboard keys, and so might be unusable for what you want to do. But there's only one way to find out for sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants