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

Regular keys break is_pressed on Mac #662

Open
mqw opened this issue Dec 15, 2024 · 0 comments
Open

Regular keys break is_pressed on Mac #662

mqw opened this issue Dec 15, 2024 · 0 comments

Comments

@mqw
Copy link

mqw commented Dec 15, 2024

On my Mac keyboard.is_pressed('escape') works, keyboard.is_pressed('f') does not.

  File "/opt/homebrew/lib/python3.11/site-packages/keyboard/__init__.py", line 324, in key_to_scan_codes
    raise ValueError('Key {} is not mapped to any known key.'.format(repr(key)), e)
ValueError: ("Key 'f' is not mapped to any known key.", ValueError('Unrecognized character: f'))

Digging through code I have found that:

print(keyboard._os_keyboard.key_controller.key_map.non_layout_keys)
print(keyboard._os_keyboard.key_controller.key_map.layout_specific_keys)

prints

{36: 'enter', 48: 'tab', 49: 'space', 51: 'delete', 53: 'esc', 55: 'command', 56: 'shift', 57: 'caps lock', 58: 'alt', 59: 'ctrl', 60: 'right shift', 61: 'right option', 62: 'right ctrl', 63: 'ƒ', 64: 'f17', 72: 'volume up', 73: 'volume down', 74: 'mute', 79: 'f18', 80: 'f19', 90: 'f20', 96: 'f5', 97: 'f6', 98: 'f7', 99: 'f3', 100: 'f8', 101: 'f9', 103: 'f11', 105: 'f13', 106: 'f16', 107: 'f14', 109: 'f10', 111: 'f12', 113: 'f15', 114: 'help', 115: 'home', 116: 'page up', 117: 'forward delete', 118: 'f4', 119: 'end', 120: 'f2', 121: 'page down', 122: 'f1', 123: 'left', 124: 'right', 125: 'down', 126: 'up'}
{0: ('', ''), 1: ('', ''), 2: ('', ''), 3: ('', ''), 4: ('', ''), 5: ('', ''), 6: ('', ''), 7: ('', ''), 8: ('', ''), 9: ('', ''), 10: ('', ''), 11: ('', ''), 12: ('', ''), 13: ('', ''), 14: ('', ''), 15: ('', ''), 16: ('', ''), 17: ('', ''), 18: ('', ''), 19: ('', ''), 20: ('', ''), 21: ('', ''), 22: ('', ''), 23: ('', ''), 24: ('', ''), 25: ('', ''), 26: ('', ''), 27: ('', ''), 28: ('', ''), 29: ('', ''), 30: ('', ''), 31: ('', ''), 32: ('', ''), 33: ('', ''), 34: ('', ''), 35: ('', ''), 36: ('', ''), 37: ('', ''), 38: ('', ''), 39: ('', ''), 40: ('', ''), 41: ('', ''), 42: ('', ''), 43: ('', ''), 44: ('', ''), 45: ('', ''), 46: ('', ''), 47: ('', ''), 48: ('', ''), 49: ('', ''), 50: ('', ''), 51: ('', ''), 52: ('', ''), 53: ('', ''), 54: ('', ''), 55: ('', ''), 56: ('', ''), 57: ('', ''), 58: ('', ''), 59: ('', ''), 60: ('', ''), 61: ('', ''), 62: ('', ''), 63: ('', ''), 64: ('', ''), 65: ('', ''), 66: ('', ''), 67: ('', ''), 68: ('', ''), 69: ('', ''), 70: ('', ''), 71: ('', ''), 72: ('', ''), 73: ('', ''), 74: ('', ''), 75: ('', ''), 76: ('', ''), 77: ('', ''), 78: ('', ''), 79: ('', ''), 80: ('', ''), 81: ('', ''), 82: ('', ''), 83: ('', ''), 84: ('', ''), 85: ('', ''), 86: ('', ''), 87: ('', ''), 88: ('', ''), 89: ('', ''), 90: ('', ''), 91: ('', ''), 92: ('', ''), 93: ('', ''), 94: ('', ''), 95: ('', ''), 96: ('', ''), 97: ('', ''), 98: ('', ''), 99: ('', ''), 100: ('', ''), 101: ('', ''), 102: ('', ''), 103: ('', ''), 104: ('', ''), 105: ('', ''), 106: ('', ''), 107: ('', ''), 108: ('', ''), 109: ('', ''), 110: ('', ''), 111: ('', ''), 112: ('', ''), 113: ('', ''), 114: ('', ''), 115: ('', ''), 116: ('', ''), 117: ('', ''), 118: ('', ''), 119: ('', ''), 120: ('', ''), 121: ('', ''), 122: ('', ''), 123: ('', ''), 124: ('', ''), 125: ('', ''), 126: ('', ''), 127: ('', '')}

The latter dicts values are not set in KeyMap class __init__

for key_code in range(0, 128):
  non_shifted_char = UniChar4()
  shifted_char = UniChar4()
  keys_down = ctypes.c_uint32()
  char_count = UniCharCount()

I have tried just filling the constructor parameters, but it is not sufficient - it does prevent the error, but keyboard.is_pressed('f') still does not work.

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