0

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

clt60
  • 62,119
  • 17
  • 107
  • 194
  • you can try this debug print for hammerspoon: https://github.com/Hammerspoon/hammerspoon/issues/2937#issuecomment-929830848 - but the code also assume that the key is in the keymap - but maybe you get a hint when you print the `event:getKeyCode()` – muescha Jun 10 '23 at 19:50
  • even if you can not find an mapping - you can use the event watcher `hs.eventtap.new` to do actions when you see a keypress – muescha Jun 10 '23 at 19:57

1 Answers1

1

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.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 24 '22 at 05:45