【发布时间】:2021-04-13 22:37:14
【问题描述】:
早上好, 我正在使用 Python 的 3.8 pynput(在 Windows 10 中)来获取每次输入的字符(在系统级别),然后是该字符的 unicode。
from pynput import keyboard
def on_press(key):
if key == keyboard.Key.esc: #if button escape is pressed close the program
listener.stop()
else: #if button escape is not pressed get the unicode code of the button-char pressed
unicode_code = ord(getattr(key, 'char', '0'))
print("The unicode is ",unicode_code)
print("The char entered is",chr(unicode_code))
controller = keyboard.Controller()
# Collect events until released
with keyboard.Listener(on_press=on_press) as listener:
listener.join()
我面临的问题是,当我将键盘更改为希腊语(使用 shift+alt)时,它会保留英语的 unicode,而不是希腊语的 unicode。 您可以查看随附的屏幕截图以更好地理解。
如何解决这个问题?
【问题讨论】:
标签: python python-3.x keyboard pynput