gpt4 book ai didi

python - 如何将输入作为左箭头键输入?

转载 作者:太空狗 更新时间:2023-10-30 02:14:05 25 4
gpt4 key购买 nike

我想将左右箭头键作为输入之一。我怎么才能得到它?有什么办法吗?

最佳答案

使用 Tkinter 你可以做以下事情....我在网上找到的

# KeyLogger_tk2.py
# show a character key when pressed without using Enter key
# hide the Tkinter GUI window, only console shows

try:
# Python2
import Tkinter as tk
except ImportError:
# Python3
import tkinter as tk

def key(event):
"""shows key or tk code for the key"""
if event.keysym == 'Escape':
root.destroy()
if event.char == event.keysym:
# normal number and letter characters
print( 'Normal Key %r' % event.char )
elif len(event.char) == 1:
# charcters like []/.,><#$ also Return and ctrl/key
print( 'Punctuation Key %r (%r)' % (event.keysym, event.char) )
else:
# f1 to f12, shift keys, caps lock, Home, End, Delete ...
print( 'Special Key %r' % event.keysym )


root = tk.Tk()
print( "Press a key (Escape key to exit):" )
root.bind_all('<Key>', key)
# don't show the tk window
root.withdraw()
root.mainloop()

关于python - 如何将输入作为左箭头键输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4204714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com