pynput icon indicating copy to clipboard operation
pynput copied to clipboard

Unable to get key combination in string format in keyboard.Listener()

Open i-am-unknown-81514525 opened this issue 2 years ago • 0 comments

Description I cannot get a key conbination in string form like "Ctrl+Z" but it give a unicode liked item "\x1a" How am I able to decode this ? Any program way can do that?

Platform and pynput version Its Window 10 and pynput 1.7.6

To Reproduce On Press part:

def on_press(key):
    try:
        #print(key.char,end="")
        key.char
        print(str(key)[1:-1],end="")
    except AttributeError:
        key = str(key)
        if key == "Key.enter":
            print("[Enter]")
        elif key == "Key.space":
            print(" ",end="")
        elif key == "Key.shift":
            print("[SHIFT]")
        elif key == "Key.backspace":
            print("[BACKSPACE]")
        elif key == "Key.caps_lock":
            print("[Cap_Lock]")
        elif key == "Key.right":
            print("[Right]")
        elif key == "Key.left":
            print("[Left]")
        #...(Other key item)
        else:
            print('special key {0} pressed'.format(
            key))

i-am-unknown-81514525 avatar Mar 08 '22 17:03 i-am-unknown-81514525