python 鼠标键盘消息
python操作鼠标键盘
使用pyautogui 或pynput
1.禁用键盘鼠标(测试未禁用笔记本触摸区域)
1 from ctypes import * 2 #禁用鼠标键盘 3 windll.user32.BlockInput(1) 4 5 #接禁鼠标键盘 6 windll.user32.BlockInput(0)
2.发送键盘消息
1 import pyautogui 2 from pynput.keyboard import Controller,Key 3 # method1 4 pyautogui.press('enter') 5 # method2 6 keyboard = Controller() 7 keyboard.press(Key.enter) 8 keyboard.release(Key.enter)
3.发送字符串消息
1 from pynput.keyboard import Controller,Key 2 from ctypes import * 3 # 禁用键盘鼠标 4 windll.user32.BlockInput(1) 5 keyboard = Controller() 6 # 发送字符带回车 7 pyautogui.typewrite("abcd\n") 8 # 启用键盘鼠标 9 windll.user32.BlockInput(0)