Key codes identify physical keys, while characters depend on the keyboard layout. map and
names follow the current layout, so on Dvorak map["w"] is the key code of the key that
types w there.
// Look up a keycode by name constcode = hs.keycodes.map["a"] // e.g. 0 on ANSI US // Look up a name by keycode constname = hs.keycodes.names[0] // e.g. "a"
Switching layouts
hs.keycodes.setLayout("British")
Watching for input source changes
hs.keycodes.on('change', () => { console.log("Switched to: " + hs.keycodes.currentLayout()) })
Access information about the current keyboard layout and input sources, and respond to changes.
Reading the current layout
Key code mapping
Key codes identify physical keys, while characters depend on the keyboard layout.
mapandnamesfollow the current layout, so on Dvorakmap["w"]is the key code of the key that typeswthere.Switching layouts
Watching for input source changes