You've already forked AiraPulsar
minor improv.
This commit is contained in:
27
testfield/kbemu/1.py
Normal file
27
testfield/kbemu/1.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import time
|
||||
from pynput.keyboard import Controller
|
||||
import threading
|
||||
|
||||
# 创建键盘控制器
|
||||
keyboard = Controller()
|
||||
|
||||
def press_keys():
|
||||
while True: # 持续循环
|
||||
keyboard.press('1') # 按下 'w' 键
|
||||
time.sleep(0.5) # 等待0.5秒
|
||||
keyboard.release('w') # 释放 'w' 键
|
||||
keyboard.press('d') # 按下 'd' 键
|
||||
time.sleep(0.5) # 等待0.5秒
|
||||
keyboard.release('d') # 释放 'd' 键
|
||||
|
||||
# 创建并启动线程
|
||||
thread = threading.Thread(target=press_keys)
|
||||
thread.daemon = True # 设置为守护线程
|
||||
thread.start()
|
||||
|
||||
# 主线程可以在这里执行其他操作
|
||||
try:
|
||||
while True:
|
||||
time.sleep(1) # 主线程保持运行
|
||||
except KeyboardInterrupt:
|
||||
print("程序已停止。")
|
Reference in New Issue
Block a user