Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numpad keys are not usable for hotkeys #1640

Open
imawizard opened this issue May 10, 2024 · 0 comments
Open

Numpad keys are not usable for hotkeys #1640

imawizard opened this issue May 10, 2024 · 0 comments

Comments

@imawizard
Copy link

Describe the bug
My keyboard layout has no numbers like e.g. kVK_ANSI_2 mapped and Amethyst doesn't make use of numpad keys, so the following config file doesn't work for me:

select-wide-layout:
  mod: mod1
  key: "2"

Additional context

UCKeyTranslate(layout,
UInt16(keyCode),
UInt16(kUCKeyActionDisplay),
0,
UInt32(LMGetKbdType()),
UInt32(kUCKeyTranslateNoDeadKeysBit),
&keysDown,
chars.count,
&realLength,
&chars)
let string = CFStringCreateWithCharacters(kCFAllocatorDefault, chars, realLength) as String
if let keyCodes = stringToKeyCodes[string] {
var mutableKeyCodes = keyCodes
mutableKeyCodes.append(keyCode)
stringToKeyCodes[string] = mutableKeyCodes
} else {
stringToKeyCodes[string] = [keyCode]
}

This code results in stringToKeyCodes[""] = [kVK_ANSI_2] for me, thus I get the error String "2" does not map to any keycodes later on.

I do have the numpad keys mapped, though, so it could result in stringToKeyCodes["2"] = [kVK_ANSI_Keypad2] instead, if the following switch wouldn't explicitly ignore numpad keys:

switch keyCode {
case
kVK_ANSI_Keypad0,
kVK_ANSI_Keypad1,
kVK_ANSI_Keypad2,
kVK_ANSI_Keypad3,
kVK_ANSI_Keypad4,
kVK_ANSI_Keypad5,
kVK_ANSI_Keypad6,
kVK_ANSI_Keypad7,
kVK_ANSI_Keypad8,
kVK_ANSI_Keypad9:
continue
default:
break
}

What's the reason behind this? AFAIK removing it wouldn't break anything:

  1. if one has both keys mapped, it'd result in stringToKeyCodes["2"] = [kVK_ANSI_2, kVK_ANSI_Keypad2] because kVK_ANSI_2 < kVK_ANSI_Keypad2
  2. the function registering the hotkey is only using the first key code, so it wouldn't use the numpad key code
    let shortcut = MASShortcut(keyCode: keyCodes[0], modifierFlags: modifiers)

Versions:

  • macOS: 14.4.1
  • Amethyst: 0.20.0

PS: The following seems to be dead code, doesn't it?

private static func keyCodeForNumber(_ number: NSNumber) -> AMKeyCode {
let string = "\(number)"
guard !string.isEmpty else {
return AMKeyCodeInvalid
}
switch string.last! {
case "1":
return kVK_ANSI_1
case "2":
return kVK_ANSI_2
case "3":
return kVK_ANSI_3
case "4":
return kVK_ANSI_4
case "5":
return kVK_ANSI_5
case "6":
return kVK_ANSI_6
case "7":
return kVK_ANSI_7
case "8":
return kVK_ANSI_8
case "9":
return kVK_ANSI_9
case "0":
return kVK_ANSI_0
default:
return AMKeyCodeInvalid
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant