Hammerspoon / hammerspoon

Staggeringly powerful macOS desktop automation with Lua
http://www.hammerspoon.org
MIT License
11.72k stars 579 forks source link

access to Japanese input source details #2034

Open belm0 opened 5 years ago

belm0 commented 5 years ago

The "Japanese" input source contains various configuration, most important of which is "Romaji layout" which determines the underlying keyboard layout. So if you want Japanese input to work on multiple keyboards having different layouts, you'd need to set this configuration.

cmsj commented 5 years ago

Is this not already covered by the layouts/methods functions in http://www.hammerspoon.org/docs/hs.keycodes.html ?

belm0 commented 5 years ago

No, I don't believe it's covered. This is a setting specific to the Japanese input method. (There are about 15 such settings but this one is essential since it's tied to keyboard layout.)

Whenever I execute setMethod('Hiragana'), the current layout is forced to the layout configured in "Romaji layout" field of the Japanese input settings. It's not possible for me to change the layout via setLayout(...) without the current method getting reset to nil.

> k=hs.keycodes
> for name, val in pairs(k.layouts()) do print(name, val) end
1   Dvorak
2   U.S.

> for name, val in pairs(k.methods()) do print(name, val) end
1   Hiragana

> k.setMethod('Hiragana')
true

> k.currentLayout(), k.currentMethod()
Dvorak  Hiragana

> k.setLayout('U.S.')
true

> k.currentLayout(), k.currentMethod()
U.S.    nil

> k.setMethod('Hiragana')
true

> k.currentLayout(), k.currentMethod()
Dvorak  Hiragana

screen shot 2019-03-05 at 8 33 19 pm