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)