PyUserInput icon indicating copy to clipboard operation
PyUserInput copied to clipboard

Mac needs character to keycode translation table

Open willwade opened this issue 11 years ago • 8 comments

Running this example code:

from pykeyboard import PyKeyboard k = PyKeyboard() k.type_string('Hello, World!')

Gives:

python test.py Traceback (most recent call last): File "test.py", line 3, in k.type_string('Hello, World!') File "/Library/Python/2.7/site-packages/pykeyboard/base.py", line 47, in type_string self.tap_key(i) File "/Library/Python/2.7/site-packages/pykeyboard/base.py", line 39, in tap_key self.press_key(character) File "/Library/Python/2.7/site-packages/pykeyboard/mac.py", line 22, in press_key event = CGEventCreateKeyboardEvent(None, key, True) ValueError: depythonifying 'unsigned short', got 'str'

willwade avatar Apr 07 '13 13:04 willwade

Characters are not yet implemented on Mac. So You'll have to insert keycodes for now.

Me or @SavinaRoja should write this support sometime, but patch welcome.

pepijndevos avatar Apr 07 '13 13:04 pepijndevos

Ahh cool. Apologies for hassling :)

willwade avatar Apr 07 '13 13:04 willwade

NP.

Changed the title to reflect the actual problem.

pepijndevos avatar Apr 07 '13 13:04 pepijndevos

This might be useful: https://gist.github.com/willwade/5330474 I was looking to develop something similar till I stumbled across pyuserinput

willwade avatar Apr 07 '13 13:04 willwade

Very nice. Where did you get that from?

There is some discussion about this in #1.

pepijndevos avatar Apr 07 '13 13:04 pepijndevos

From http://web.archive.org/web/20100501161453/http://www.classicteck.com/rbarticles/mackeyboard.php I'll try and get my head around how PyUserInput works and see if I have anything decent to add to the discussion in #1

Thanks!

willwade avatar Apr 07 '13 13:04 willwade

(the little csv method for doing keycodes is working pretty well in my quick 5 minute play.. you can see the implementation in convertWintoMacCode at https://github.com/willwade/MacroServerMac/blob/master/AppleUIEvents.py - one thing I've noticed though is that some of those keycodes are wrong. I'm wondering if they have a different codes on different layouts)

willwade avatar Apr 07 '13 16:04 willwade

Initial support for keycode translation on OS X added in 70419b3654950ca0188b3115964f762363d7ef93

It needs some more work and polishing.

balloob avatar Oct 09 '13 17:10 balloob