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

Unrecognized character: alt gr in add_hotkey for any key combination #117

Open
Clpsplug opened this issue Jan 7, 2018 · 6 comments
Open

Comments

@Clpsplug
Copy link

Clpsplug commented Jan 7, 2018

Environment

  • boppreh/keyboard master-branch
  • macOS 10.13.2
  • Python 3.6.2

What happened

If I use add_hotkey for my app, keyboard spits Unrecognized character: alt gr whenever I press the first combination with U.S. IME, preventing detection of further keypresses. It doesn't matter if my hotkey ever needs alt-gr keys. Does this have any connection with #103?

Expected behavior

The script shouldn't crash, at least when there are no modifiers involved in the hotkey.

To reproduce

The minimum code to reproduce the issue is as follows:

import keyboard
# Notice the hotkey never requiring modifiers
keyboard.add_hotkey('t,e,s,t', lambda: print('Success!'))

Type that into python interactive shell, then type t for the crash. 'Success!' never prints out. Thanks to the procedure being in the different thread, the script itself doesn't crash, though.

The final 3 calls are (path modified to hide private directories:)

   File "./src/keyboard/keyboard/_darwinkeyboard.py", line 421, in map_char
     return key_controller.map_char(character)
   File "./src/keyboard/keyboard/_darwinkeyboard.py", line 336, in map_char
     return self.key_map.character_to_vk(character)
   File "./src/keyboard/keyboard/_darwinkeyboard.py", line 184, in character_to_vk
     raise ValueError("Unrecognized character: {}".format(character))
@glitchassassin glitchassassin self-assigned this Jan 10, 2018
@glitchassassin
Copy link
Collaborator

Confirmed this issue on my side. Checking if there is an AltGr key in OS X, or if it should be ignored...

@glitchassassin
Copy link
Collaborator

glitchassassin commented Jan 10, 2018

From what I can turn up, OS X does not recognize the AltGr key separately from the regular Alt key. There are two possible solutions:

  1. Remove the AltGr key from the all_modifiers list altogether on OS X.
    • Causes an exception when running cross-platform code that hooks the AltGr key.
  2. Or, map the AltGr key to the regular Alt key on OS X.
    • This could cause unexpected behavior when running cross-platform code that hooks the AltGr key.

I think option 1 is the clearest for developers, and alerts them to the need to redesign AltGr-dependent code to run on OS X. @boppreh, official ruling?

@boppreh
Copy link
Owner

boppreh commented Mar 30, 2018

Seems like I dropped the ball on this one, sorry for not replying.

The library is built to be forgiving, for example by including aliases of common functions, and normalizing key names automatically. I think mapping AltGr to Alt is the least bad option.

I've updated _canonical_names, please let me know if it solves the problem.

PS: excellent bug report format from Clpsplug

@Clpsplug
Copy link
Author

Clpsplug commented Apr 23, 2018

I just realized this, I'll be sure to try it after I finish my things :)

@Clpsplug
Copy link
Author

Clpsplug commented May 24, 2018

Hmm, I finally got some time to check this, and in the interactive shell I did this:

import keyboard
keyboard.add_hotkey('t,e,s,t', lambda: print('Success!'))

I typed test. The crash was gone; However, nothing typed out after typing test. Now I'm starting to suspect I made a serious misunderstanding somewhere. This code, even in the interactive shell, will print 'Success!' anytime I type test, right?

I am using:

  • MacOS High Sierra 10.13.4.
  • boppreh/keyboard 0.13.2

@glitchassassin
Copy link
Collaborator

This code does not appear to work on the current version of keyboard in either Windows or Mac. It did work in a previous version of keyboard (0.11.0). This is probably a hotkey issue rather than an OS-specific issue.

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

No branches or pull requests

3 participants