1、先安装模块PyUserInput
pip install PyUserInput -i https://pypi.mirrors.ustc.edu.cn/simple/
pip install pypiwin32 -i https://pypi.mirrors.ustc.edu.cn/simple/
2、使用
常用函数介绍:
press_key() # 按下键 release_key() # 松开键 press_keys() # 按下多个键,参数为列表
按键示例:
k.press_key('i') # 模拟键盘按i键 k.press_key(k.alt_key) # 按住alt键 k.press_key(k.control_key) # 按住ctrl键 k.press_key(k.enter_key) # 按住enter键 k.tap_key(k.tab_key) # 点击tab键 k.tap_key(k.delete_key) # 点击delete键 k.release_key(k.alt_key) # 松开alt键 k.tap_key(k.function_keys[5]) # 点击功能键F5 k.tap_key(k.numpad_keys[5],2) # 点击小键盘5共2次 k.type_string('Hello, World!') #输入内容
简单用例:
from pykeyboard import PyKeyboard k = PyKeyboard() #按向下的方向键 k.press_key(k.down_key) #按回车键 k.press_key(k.enter_key)