So trying to load a key from a text file works fine. Adding it to another string property works fine. Converting it back to a keycode (so that you can change the key in a keyboard sensor), is an absolute nightmare.
Let my loss of 20minutes be your gain:
key_dict = {'A':97, 'B':98, 'C':99, 'D':100, 'E':101, 'F':102, 'G':103, 'H':104, 'I':105, 'J':106, 'K':107, 'L':108, 'M':109, 'N':110, 'O':111, 'P':112, 'Q':113, 'R':114, 'S':115, 'T':116, 'U':117, 'V':118, 'W':119, 'X':120, 'Y':121, 'Z':122, 'LEFTARROW':143, 'DOWNARROW':144, 'RIGHTARROW':145, 'UPARROW':146, 'F1':162, 'F2':163, 'F3':164, 'F4':165, 'F5':166, 'F6':167, 'F7':168, 'F8':169, 'F9':170, 'F10':171, 'F11':182, 'F12':183, 'ZERO':48, 'ONE':49, 'TWO':50, 'THREE':51, 'FOUR':52, 'FIVE':53, 'SIX':54, 'SEVEN':55, 'EIGHT':56, 'NINE':57, 'PAD0':158, 'PAD1':151, 'PAD2':147, 'PAD3':152, 'PAD4':148, 'PAD5':153, 'PAD6':149, 'PAD7':154, 'PAD8':150, 'PAD9':155, 'PADPERIOD':156, 'PADSLASH':157, 'PADASTER':42, 'PADMI':159, 'PADPLUS':161, 'PADEN':160, 'ACCENTGRAVE':137, 'BACKSLASH':139, 'BACKSPACE':133, 'COMMA':44, 'DEL':134, 'END':186, 'EQUAL':140, 'ESC':130, 'HOME':176, 'INSERT':175, 'LEFTBRACKET':141, 'LINEFEED':132, 'MINUS':45, 'PAGEDOWN':178, 'PAGEUP':177, 'PAUSE':174, 'PERIOD':46, 'QUOTE':136, 'RIGHTBRACKET':142, 'RET':13, 'SEMICOLON':135, 'SLASH':138, 'TAB':131, 'LEFTCTRL':124, 'LEFTALT':125, 'RIGHTALT':126, 'RIGHTCTRL':127, 'RIGHTSHIFT':128, 'LEFTSHIFT':129, 'SPACE':32}
How to use:
***This dictionary assumes when you wrote the key to a file, you removed the last 3 letters.
So if I wanted to save the w key:
get the key
wkey = bge.event.WKEY
remove the last 3 letters (usually ‘KEY’)
wkey = wkey[:-3]
Write wkey to file
A couple keys such as the PADMINUS don’t have KEY at the end, this means that they are reduced to PADMI instead (this has been accounted for in the dictionary).
To retrieve a keycode simply put:
keycode = key_dict[keystring]
Where ‘keystring’ is the loaded ‘key’ from the file. In this example case you would load in ‘W’:
keycode = key_dict['W']
Any duplicates or issues or anything else let me know and I will update it.