python - 是否可以在没有任何导入模块/库的情况下在 Python 中模拟按键
问题描述
我正在使用 Python(2.4)并尝试模拟按键(CTRL,SHIFT)。但是我的 python 内置在一个媒体应用程序/框架中(来自 Peavey),它允许我在 Python 中进行非常基本的编码,但没有安装/导入任何模块、库的能力。
所以我不能使用任何库/模块进行按键操作,例如:键盘、pyinput、ctype、Win32、wintype 等。
有什么方法可以在不使用脚本顶部的“导入”的情况下模拟按键?
先感谢您...
我尝试了以下方法:
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
当我在生产中使用代码时,我无法导入库。
解决方案
推荐阅读
- r - R中的数据字典链接
- c++ - 禁用 Visual Studio 绿色箭头按钮移动指令指针
- node.js - 从 Next.js 中的 CMS 访问 api
- monaco-editor - 如何在当前视口滚动时获取摩纳哥编辑器中第一条可见行的行号?
- javascript - Vuejs:如何有条件地附加道具?
- css - Vutify 中的不同视口
- python - 如何在python中拆分文本计数字符串列表中的出现次数
- amazon-web-services - 使用数据库脚本将 JSON 数组导入 DynamoDB 表
- android - android 库中的 assembleRelease 任务“:verifyReleaseResources”执行失败
- json - oc 补丁替换图像名称错误“json:无法将对象解组为 jsonpatch.Patch 类型的 Go 值”