python监听鼠标键盘_python用pynput监听控制键盘鼠标

安装

pip install pynput

from pynput import mouse,keyboard

# mouse.Button;

# mouse.Controller;

# keyboard.Key;

# keyboard.Controller;

# controller=mouse.Controller();

# # 获取鼠标位置

# print(controller.position);

# # # 定位

# controller.position=(0,20);

# # # 移动

# controller.move(150,32)

# # 单击右键

# controller.click(mouse.Button.right,1)

# # 双击左键

# controller.click(mouse.Button.left,2)

# # 按住左键

# controller.press(mouse.Button.left)

# # 释放左键

# controller.release(mouse.Button.left)

# 鼠标滚动,负数往下滚

# controller.scroll(0,-100);

def on_move(x,y):

print(x,y)

def on_click(x,y,button,pressed):

print(x,y)

def on_scroll(x,y,dx,dy):

print(x,y)

# #监听鼠标

# with mouse.Listener(on_move=on_move,on_click=on_click,on_scroll=on_scroll) as listener:

# listener.join()

# 停止监听,或者在回调中返回False

# mouse.Listener.stop()

# #以下是键盘

# #控制键盘

keyboardController=keyboard.Controller();

# 按住空格

keyboardController.press(keyboard.Key.space);

# 松开空格键

keyboardController.release(keyboard.Key.space);

# 按住a

keyboardController.press('a');

keyboardController.release('a');

def on_press(key):

print(key);

def on_release(key):

print(key);

# # 监听键盘按键

# with keyboard.Listener(on_press=on_press,on_release=on_release) as listener:

# listener.join()

# 停止监听,或者在回调中返回False

# keyboard.Listener.stop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值