type(list[0]) returns pynput.keyboard._win32.KeyCode

后端 未结 1 384
误落风尘
误落风尘 2021-01-28 08:33

My problem is how pynput returns the data (I hope that\'s how you would say it?).

So what I\'m trying to do is have the listener record keyboard input, the

相关标签:
1条回答
  • 2021-01-28 08:55

    You can extract the character from the pressed key by using the char attribute of the pynput.keyboard._win32.KeyCode. In other words, in your press function, you would append key.char to the list. Also, I would avoid using list as a variable name.

    def press(key):
        print(_list, 'pressed')
        if key is not keyboard.Key.space:
            _list.append(key.char)         # <-- Note: key.char
        elif keyboard.Key.space is key:
            pass
    elif keyboard.Key.enter is key:
        pass
    
    0 讨论(0)
提交回复
热议问题