hammerspoonkarabiner

Using unknown/undefined keyboard (keymap) in hammerspoon


I have attached to my mac a keyboard with additional (nonstandard) keys. See the image at the end of post.

Here is my testing Hammerspoon init.lua

local hyper = {"cmd", "alt", "ctrl", "shift"}
hs.hotkey.bind(hyper, "E", function()
    hs.alert.show("Hyper E")
end)

hs.hotkey.bind(nil, "help", function()
    hs.alert.show("HELP")   -- works
end)

-- hs.hotkey.bind(nil, "copy", function()
--  hs.alert.show("COPY")   -- error
-- end)

If uncommenting the above block, the reload showing error:

2022-11-28 11:28:06: *** ERROR: ...merspoon.app/Contents/Resources/extensions/hs/hotkey.lua:415: Invalid key: copy - this may mean that the key requested does not exist in your keymap (particularly if you switch keyboard layouts frequently)

The Macos silently ignoring the nonstandard keys. (probably because no valid keymap definition file exists).

However, the Karabiner-Elements correctly find all keys. This is a copy from the event-watcher.

[
  {
    "type": "down",
    "name": {"key_code":"help"},
    "usagePage": "7 (0x0007)",
    "usage": "117 (0x0075)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"help"},
    "usagePage": "7 (0x0007)",
    "usage": "117 (0x0075)",
    "misc": ""
  },
  {
    "type": "down",
    "name": {"key_code":"stop"},
    "usagePage": "7 (0x0007)",
    "usage": "120 (0x0078)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"stop"},
    "usagePage": "7 (0x0007)",
    "usage": "120 (0x0078)",
    "misc": ""
  },
  {
    "type": "down",
    "name": {"key_code":"again"},
    "usagePage": "7 (0x0007)",
    "usage": "121 (0x0079)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"again"},
    "usagePage": "7 (0x0007)",
    "usage": "121 (0x0079)",
    "misc": ""
  },
  {
    "type": "down",
    "name": {"key_code":"menu"},
    "usagePage": "7 (0x0007)",
    "usage": "118 (0x0076)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"menu"},
    "usagePage": "7 (0x0007)",
    "usage": "118 (0x0076)",
    "misc": ""
  },
  {
    "type": "down",
    "name": {"key_code":"undo"},
    "usagePage": "7 (0x0007)",
    "usage": "122 (0x007a)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"undo"},
    "usagePage": "7 (0x0007)",
    "usage": "122 (0x007a)",
    "misc": ""
  },
  {
    "type": "down",
    "name": {"key_code":"select"},
    "usagePage": "7 (0x0007)",
    "usage": "119 (0x0077)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"select"},
    "usagePage": "7 (0x0007)",
    "usage": "119 (0x0077)",
    "misc": ""
  },
  {
    "type": "down",
    "name": {"key_code":"copy"},
    "usagePage": "7 (0x0007)",
    "usage": "124 (0x007c)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"copy"},
    "usagePage": "7 (0x0007)",
    "usage": "124 (0x007c)",
    "misc": ""
  },
  {
    "type": "down",
    "name": {"key_code":"execute"},
    "usagePage": "7 (0x0007)",
    "usage": "116 (0x0074)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"execute"},
    "usagePage": "7 (0x0007)",
    "usage": "116 (0x0074)",
    "misc": ""
  },
  {
    "type": "down",
    "name": {"key_code":"paste"},
    "usagePage": "7 (0x0007)",
    "usage": "125 (0x007d)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"paste"},
    "usagePage": "7 (0x0007)",
    "usage": "125 (0x007d)",
    "misc": ""
  },
  {
    "type": "down",
    "name": {"key_code":"find"},
    "usagePage": "7 (0x0007)",
    "usage": "126 (0x007e)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"find"},
    "usagePage": "7 (0x0007)",
    "usage": "126 (0x007e)",
    "misc": ""
  },
  {
    "type": "down",
    "name": {"key_code":"cut"},
    "usagePage": "7 (0x0007)",
    "usage": "123 (0x007b)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"key_code":"cut"},
    "usagePage": "7 (0x0007)",
    "usage": "123 (0x007b)",
    "misc": ""
  },
  {
    "type": "down",
    "name": {"pointing_button":"button1"},
    "usagePage": "9 (0x0009)",
    "usage": "1 (0x0001)",
    "misc": ""
  },
  {
    "type": "up",
    "name": {"pointing_button":"button1"},
    "usagePage": "9 (0x0009)",
    "usage": "1 (0x0001)",
    "misc": ""
  }
]

The question: could use this keyboard in hammerspoon - e.g. bind let say the copy key. without creating macos's keymap file, only using Karabiner?

Because one image = 1000 words, here is the pic of my kbd.

enter image description here


Solution

  • Hammerspoon only recognizes, and thus supports, a specific list of keys. You can find that list in the Hammerspoon docs. I don't see copy in that list so it is no surprise it doesn't work. I'd suggest filing a GitHub issue requesting its addition, and in the meantime, using Karabiner as a workaround.