hammerspoon2-docs
    Preparing search index...

    Namespace keycodes

    Access information about the current keyboard layout and input sources, and respond to changes.

    console.log("Layout: " + hs.keycodes.currentLayout())
    console.log("Source ID: " + hs.keycodes.currentSourceID())

    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
    const code = hs.keycodes.map["a"] // e.g. 0 on ANSI US
    // Look up a name by keycode
    const name = hs.keycodes.names[0] // e.g. "a"
    hs.keycodes.setLayout("British")
    
    hs.keycodes.on('change', () => {
    console.log("Switched to: " + hs.keycodes.currentLayout())
    })
    map
    names
    currentLayout
    currentMethod
    currentSourceID
    layouts
    methods
    off
    on
    once
    setLayout
    setMethod
    setSourceID