mjolnirapp / mjolnir

Lightweight automation and productivity app for OS X
5.2k stars 129 forks source link

Error when binding Cmd-§ #544

Closed sheijk closed 5 years ago

sheijk commented 9 years ago

The following code causes an error:

hotkey.bind({"cmd"}, "§", function()
  local win = window.focusedwindow()
  local f = win:frame()
  f.x = f.x - 10
  win:setframe(f)
end)

error message:

Welcome to the Mjolnir Console!
You can run any Lua code in here.

-- Loading ~/.mjolnir/init.lua
-- Done.
-- Loading ~/.mjolnir/init.lua
-- Done.
-- Loading ~/.mjolnir/init.lua
-- Done.
-- Loading ~/.mjolnir/init.lua
/usr/local/share/lua/5.2/mjolnir/hotkey.lua:35: bad argument #2 to '_new' (number expected, got nil)
stack traceback:
    [C]: in function '_new'
    /usr/local/share/lua/5.2/mjolnir/hotkey.lua:35: in function 'new'
    /usr/local/share/lua/5.2/mjolnir/hotkey.lua:43: in function 'bind'
    /Users/jr/.mjolnir/init.lua:13: in main chunk
    [C]: in function 'xpcall'
    ...lications/Tools/Mjolnir.app/Contents/Resources/setup.lua:73: in main chunk
-- Loading ~/.mjolnir/init.lua
-- Done.
-- Loading ~/.mjolnir/init.lua
/usr/local/share/lua/5.2/mjolnir/hotkey.lua:35: bad argument #2 to '_new' (number expected, got nil)
stack traceback:
    [C]: in function '_new'
    /usr/local/share/lua/5.2/mjolnir/hotkey.lua:35: in function 'new'
    /usr/local/share/lua/5.2/mjolnir/hotkey.lua:43: in function 'bind'
    /Users/jr/.mjolnir/init.lua:13: in main chunk
    [C]: in function 'xpcall'
    ...lications/Tools/Mjolnir.app/Contents/Resources/setup.lua:73: in main chunk
-- Loading ~/.mjolnir/init.lua
/usr/local/share/lua/5.2/mjolnir/hotkey.lua:35: bad argument #2 to '_new' (number expected, got nil)
stack traceback:
    [C]: in function '_new'
    /usr/local/share/lua/5.2/mjolnir/hotkey.lua:35: in function 'new'
    /usr/local/share/lua/5.2/mjolnir/hotkey.lua:43: in function 'bind'
    /Users/jr/.mjolnir/init.lua:13: in main chunk
    [C]: in function 'xpcall'
    ...lications/Tools/Mjolnir.app/Contents/Resources/setup.lua:73: in main chunk

Happens with other modifier keys (alt, ctrl, combinations of them) as well. The problem seems to be the "§" key (left to 1 on US international keyboard layout.

cmsj commented 9 years ago

That keycode isn't currently supported by the keycodes module. I have a patch available, from fixing it in Hammerspoon's keycodes module. The diff ought to apply cleanly to Mjolnir's keycodes module :)

https://github.com/Hammerspoon/hammerspoon/commit/07baa13daf37a5df9b8329777e5a3ef21647915f

thesoftwarephilosopher commented 9 years ago

@sheijk The hotkey.bind function was designed so that you specify exactly what key your keyboard shows. Most keyboards don't have a key dedicated to the "§" character, instead relying on combinations of keys being pressed to get this. You'd write those instead. For example, if you had to press Option + S to print "§", then you'd use {"alt"} as the mods and "s" as the key in the bind function.

thesoftwarephilosopher commented 9 years ago

@sheijk Alternatively you can use @cmsj's app or just apply his patch to Mjolnir, either one. He's apparently on top of it.

cmsj commented 9 years ago

@Sdegutis (US ISO Mac keyboards, and many international Mac keyboards, do have a key for that, weirdly!)

sheijk commented 9 years ago

Cool. So what is the relation of mjolnir and hammerspoon? The history looks like development moved to the latter or is it a complete fork? The FAQ and sites etc. seems to be quite shy about the issue..

thesoftwarephilosopher commented 9 years ago

@sheijk Some people strongly objected to many aspects of Mjolnir and its maintainer (me), and decided to take it upon themselves to fix these things. Thus Hammerspoon was born.

thesoftwarephilosopher commented 9 years ago

@sheijk Also, due to the nature of Mjolnir, development on the core app is no longer necessary, as all new features can be added via external modules or "plugins". That's why development looks to have halted when in fact it continues within the community.