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

Adding a key with a localized name on Windows makes all other keys raise errors. #56

Closed
obskyr opened this issue Apr 5, 2017 · 3 comments

Comments

@obskyr
Copy link

obskyr commented Apr 5, 2017

  • OS: 64-bit Windows 10
  • System locale: Swedish
  • keyboard version: 0.9.13

This simple line of code causes big problems on my system:

keyboard.add_hotkey('up', lambda: print("Registered."))

("up" may be substituted with "up arrow", "down", "down arrow", "left", "left arrow", "right", or "right arrow" to get the same result).

After running this, pressing the specified arrow key works as expected and calls the callback. Pressing literally any other key on the keyboard, however, raises an error with the following traceback:

Traceback (most recent call last):
  File "C:\Python36-32\lib\site-packages\keyboard\_generic.py", line 23, in invoke_handlers
    if handler(event):
  File "C:\Python36-32\lib\site-packages\keyboard\__init__.py", line 296, in handler
    unexpected = not any(matches(event, part) for part in steps[state.step])
  File "C:\Python36-32\lib\site-packages\keyboard\__init__.py", line 296, in <genexpr>
    unexpected = not any(matches(event, part) for part in steps[state.step])
  File "C:\Python36-32\lib\site-packages\keyboard\__init__.py", line 152, in matches
    return matched_name or _os_keyboard.map_char(normalized)[0] == event.scan_code
  File "C:\Python36-32\lib\site-packages\keyboard\_winkeyboard.py", line 447, in map_char
    raise ValueError('Key name {} is not mapped to any known key.'.format(repr(name)))
ValueError: Key name 'up' is not mapped to any known key.

On further inspection, this seems to be because the key names in to_scan_code are localized (wtf, Windows?). It seems to be issue #12 coming back to bite you again! I suppose you fixed the ability to add keys with localized key names - just not without every other key breaking. 😉

@boppreh
Copy link
Owner

boppreh commented Apr 6, 2017

Thankfully there are "virtual key codes", with fixed values and English names. It didn't work in this case because the up arrow is named as "up arrow" (https://github.com/boppreh/keyboard/blob/master/keyboard/_winkeyboard.py#L160) instead of just "up" as expected, but I consider that a bug.

I'll fix it in a moment.

@boppreh boppreh closed this as completed in 3996275 Apr 6, 2017
@boppreh
Copy link
Owner

boppreh commented Apr 6, 2017

Should be fixed now. By the way, "up arrow" should still work because it's considered a synonym for "up" in canonical_names.

Thank you for the bug report. If there are any problems, feel free to reopen this issue.

@boppreh
Copy link
Owner

boppreh commented Apr 6, 2017

By the way, "up arrow" wasn't working because it was being "canonicalized" to just "up" before consulting the to_scan_code table.

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

2 participants