我正在使用Python(2.4)并尝试模拟按键(CTRL,SHIFT)。但是我的python内置在Media应用程序/框架(来自Peavey)中,它使我可以使用Python进行非常基本的编码,但没有安装/导入任何模块,库的功能。
所以我不能使用任何库/模块来进行按键操作,例如:键盘,pyinput,ctype,Win32,wintype等。
是否可以在不使用脚本顶部的“导入”的情况下模拟Keypress?
提前谢谢...
我尝试了以下方法:
import keyboard # using module keyboard
while True: # making a loop
try: # used try so that if user pressed other than the given key error will not be shown
if keyboard.is_pressed('q'): # if key 'q' is pressed
print('You Pressed A Key!')
break # finishing the loop
else:
pass
except:
break # if user pressed a key other than the given key the loop will break
但是当执行时,它给我错误说明:
Traceback (most recent call last):
File "key.py", line 1, in ?
import keyboard # using module keyboard
ImportError: No module named keyboard
在生产中使用代码时,我无法导入库。