UnicodeDecodeError

For a start, perhaps consider liberally sprinting a few print(i, theseKeys[i]) statements around so you can see where any problems arise.

I suspect you should probably try and integrate that code into the last section of your own code rather than have it separate.

Also note that the trick you are using to get upper case letters (subtracting 32 from their ASCII code) is a very 20th century approach that may very well only work for English ASCII letters. You would probably be better off using a Python function like theseKeys[i].upper() to get an upper case value in a more robust way (having said that, I’m not sure exactly how it will handle Cyrillic characters).

Try something like this but am just dashing this off so no guarantees:

if len(theseKeys[i]) == 1:
    # we only have 1 char so should be a normal key, 
    # otherwise it might be 'ctrl' or similar so ignore it
    if theseKeys[i] in key_table.keys(): # only if an equivalent has been defined

        if shift_flag:
            inputText += key_table[theseKeys[i]].upper()
            shift_flag = False
        else:
            inputText += key_table[theseKeys[i]]

     i = i + 1 # not sure if this is at the right indent level
1 Like