Hammerspoon / hammerspoon

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

Configuring HS to always use a specific keyboard layout #2378

Open roeybiran opened 4 years ago

roeybiran commented 4 years ago

Hello!

I’m using two keyboard layouts on my Mac. The main one is English, and all of my Hammerspoon keybindings are specified using English letters. When I switch to the non-English layout and invoke one of the keybindings — it works, but the console shows this: 2020-05-30 13:03:50: 13:03:50 ** Warning:hs.keycode: key 'l' not found in active keymap; using ANSI-standard US keyboard layout as fallback, returning '37’ To me, keybindings being oblivious to the current layout is definitely the desired behavior. However, I was wondering if there's a way to configure HS to always the ANSI-standard US keyboard layout, or, at least, silence those warnings?

Thanks!

latenitefilms commented 4 years ago

Try:

hs.keycodes.log:setLogLevel("error")

See hs.logger for more information.

roeybiran commented 4 years ago

Hi @latenitefilms, thanks for the reply! I pasted into the console precisely what you wrote, and I’m getting the weirdest bug:

loglevel must be a string or a number
stack traceback:
    [C]: in function 'error'
    ...oon.app/Contents/Resources/extensions/hs/logger/init.lua:19: in upvalue 'toLogLevel'
    ...oon.app/Contents/Resources/extensions/hs/logger/init.lua:236: in function <...oon.app/Contents/Resources/extensions/hs/logger/init.lua:236>
    (...tail calls...)
    [C]: in function 'xpcall'
    ...app/Contents/Resources/extensions/hs/_coresetup/init.lua:467: in function <...app/Contents/Resources/extensions/hs/_coresetup/init.lua:447>

Putting a number instead of a string doesn’t help either.

Anyway, regardless of being able to silence those messages, I was hoping to just tell HS to use a specific layout and avoid the overhead involved with looking for the missing keys (but, perhaps, it isn’t possible and there’s no overhead in the first place?).

Thanks!

latenitefilms commented 4 years ago

Opps, my bad - try:

hs.keycodes.log.setLogLevel("error")

The reason why is explained here:

the logger instance created by this method is not a regular object, but a plain table with "static" functions; therefore, do not use the colon syntax for so-called "methods" in this module (as in mylogger:setLogLevel(3)); you must instead use the regular dot syntax: mylogger.setLogLevel(3)

Regarding:

I was hoping to just tell HS to use a specific layout and avoid the overhead involved with looking for the missing keys (but, perhaps, it isn’t possible and there’s no overhead in the first place?).

To be honest, I'm not sure off the top of my head.