Skip to content

Instantly share code, notes, and snippets.

@c-l-nguyen
Last active February 28, 2021 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save c-l-nguyen/7e1bd3ef3c1e39087934e9f6fd23618d to your computer and use it in GitHub Desktop.
Save c-l-nguyen/7e1bd3ef3c1e39087934e9f6fd23618d to your computer and use it in GitHub Desktop.
Hammerspoon virtual numpad for macOS
k = hs.hotkey.modal.new('ctrl-shift', 'n')
function k:entered() hs.alert'Virtual Numpad' end
function k:exited() hs.alert'Exit Virtual Numpad' end
k:bind('ctrl-shift', 'n', function() k:exit() end)
hs.fnutils.each({
{ key='j', padkey='pad1'},
{ key='k', padkey='pad2'},
{ key='l', padkey='pad3'},
{ key='u', padkey='pad4'},
{ key='i', padkey='pad5'},
{ key='o', padkey='pad6'},
{ key='7', padkey='pad7'},
{ key='8', padkey='pad8'},
{ key='9', padkey='pad9'},
{ key='m', padkey='pad0'},
{ key='/', padkey='pad+'},
{ key=';', padkey='pad-'},
{ key='p', padkey='pad*'},
{ key='0', padkey='pad/'},
}, function(vmap)
k:bind({}, vmap.key,
function() hs.eventtap.keyStroke({}, vmap.padkey, 20) end,
nil,
function() hs.eventtap.keyStroke({}, vmap.padkey, 20) end)
end
)
@c-l-nguyen
Copy link
Author

Alright I think I got it figured out. Try this config. It will make ctrl-shift-n toggle virtual numpad. (Feel free to change that.)
Just install Hammerspoon, choose "File >Open Config", paste this in, save, then go back to Hammerspooon and choose "Reload Config”. On macOS Catalina, be sure to go into System Preferences > Security & Privacy > Privacy > Accessibility > Check "Hammerspoon.app"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment