I am trying to create a program similar to Microsoft word, only heavily simplified. I need to be able to know when shift+(any key) is pressed, and display the proper value for w
If you look at the events for 'a' and 'A' while both have the key
97, you can use either the unicode
(if strictly printable characters) or mod
attribute to tell the difference.
<Event(2-KeyDown {'scancode': 0, 'window': None, 'key': 97, 'unicode': u'a', 'mod': 0})>
<Event(2-KeyDown {'scancode': 0, 'window': None, 'key': 97, 'unicode': u'A', 'mod': 1})>
Note: the mod
is different for shift
and caps lock
characters event though the unicode
will be the same.
src = r"`1234567890-=qwertyuiop[]\asdfghjkl;\'zxcvbnm,./"
dest = r'~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?'
ch = chr(event.key)
pressed = py.key.get_pressed()
if pressed[py.K_RSHIFT] or pressed[py.K_LSHIFT] and ch in src:
ch = dest[src.index(ch)]