SavinaRoja / PyUserInput

A module for cross-platform control of the mouse and keyboard in python that is simple to install and use.
GNU General Public License v3.0
1.07k stars 244 forks source link

error in mac.py #36

Open gumpcraca opened 10 years ago

gumpcraca commented 10 years ago

it appears as though midway through the character_translate_table dict we have an error: character_translate_table = { ... '\t': 0x30, 'return' = 0x24, ... as you can see, we were using : for the dict delimiter then we use = (which is obviously not supported in python)

gumpcraca commented 10 years ago

Also, after fixing that error in the source and rebuilding, I'm getting another error: Traceback (most recent call last): File "pclip.py", line 14, in kb.type_string("hello world!") File "build/bdist.macosx-10.9-intel/egg/pykeyboard/base.py", line 54, in type_string AttributeError: 'PyKeyboard' object has no attribute 'shift_key'

gumpcraca commented 10 years ago

Also suggest, to simplify things, create a class var for "<>?:"{}|~!@#$%^&*()_+" called something like unsupported_shift_chars, then reference it throughout the class rather than referencing a static string constantly

gumpcraca commented 10 years ago

Another issue: you will never type a return character on mac since in mac it would be \n or \r\n depending on version. In character_translate_table, you need to add a value for "\n" : 0x24.

I've made all the changes necessary in my local copy. My changes thus far (and this seems to work well on my mac running Mavericks. All my changes are in pykeyboard/mac.py

  1. added "\n": 0x24 to character_translate_table
  2. changed all = in character_translate_table to :
  3. added an init def to PyKeyboard code is: def init(self): self.shift_key = 'shift'
  4. in _press_normal_key removed the need to check for is_char_shifted, we handle this in base.py and that code is never executed
  5. added an if statement before the except statement in _press_normal_key: if key.lower() == "shift": time.sleep(.1) just allows MacOS to catch up after a shift is pressed or released.
willwade commented 10 years ago

Would https://github.com/abarnert/pykeycode be useful?