当前位置: 首页 > 编程日记 > 正文

二、python小功能记录——监听鼠标事件

1.原文链接

#-*- coding:utf-8 -*-
from pynput.mouse import Button, Controller## ================================================
##              控制鼠标
## ================================================
# 读鼠标坐标
mouse = Controller()
print('The current pointer position is {0}'.format(mouse.position))
# 设置鼠标坐标
mouse.position = (10, 20)
print('Now we have moved it to {0}'.format(mouse.position))
# 移动鼠标到相对位置
mouse.move(5, -5)
# 按住和放开鼠标
mouse.press(Button.left)        # 按住鼠标左键
mouse.release(Button.left)      # 放开鼠标左键
# 点击鼠标
mouse.click(Button.left, 2)     # 点击鼠标2下
# 鼠标滚轮
mouse.scroll(0, 2)              # 滚动鼠标## 监听鼠标
from pynput.mouse import Listenerdef on_move(x, y):# 监听鼠标移动print('Pointer moved to {0}'.format((x, y)))def on_click(x, y, button, pressed):# 监听鼠标点击print('{0} at {1}'.format('Pressed' if pressed else 'Released', (x, y)))if not pressed:# Stop listenerreturn Falsedef on_scroll(x, y, dx, dy):# 监听鼠标滚轮print('Scrolled {0}'.format((x, y)))# 连接事件以及释放
with Listener(on_move=on_move, on_click=on_click, on_scroll=on_scroll) as listener:listener.join()
# 一个鼠标监听器是一个线程。线程,所有的回调将从线程调用。从任何地方调用pynput.mouse.Listener.stop,或者调用pynput.mouse.Listener.StopException或从回调中返回False来停止监听器。

转载于:https://www.cnblogs.com/cvol/p/10684054.html

相关文章:

【Smart_Point】C/C++ 中智能指针

C11智能指针 目录 C11智能指针 1.1 C11智能指针介绍 1.2 为什么要使用智能指针 1.2.1 auto_ptr(C98的方案,C11已经抛弃)采用所有权模式。 1.2.2 unique_ptr 1.2.3 shared_ptr 1.2.4 weak_ptr 1.3 share_ptr和weak_ptr的核心实现 1.…

Linux 虚拟内存和物理内存的理解【转】

转自:http://www.cnblogs.com/dyllove98/archive/2013/06/12/3132940.html 首先,让我们看下虚拟内存: 第一层理解 1. 每个进程都有自己独立的4G内存空间,各个进程的内存空间具有类似的结构 2. 一个新进程建立的时候&#xff0c…

直方图变换——查找

#include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> int main() {// 图像获取及验证cv::Mat srcImage cv::imread("..\\images\\flower3.jpg");if( !srcImage.data ) return 1;//…

【C++】C/C++ 中default/delete特性

C类的特殊成员函数及default/delete特性 本文内容侧重个人理解&#xff0c;深入理解其原理推荐https://www.geeksforgeeks.org 目录 目录 C类的特殊成员函数及default/delete特性 前言 1. 构造函数和拷贝构造函数 2. 拷贝赋值运算符 3. C11特性之default关键字(P237, P4…

Celery--任务调度利器

2019独角兽企业重金招聘Python工程师标准>>> Celery文档: http://docs.jinkan.org/docs/celery/getting-started/first-steps-with-celery.html 安装celery和celery-with-redis pip install Celery pip install celery-with-redis开始编写task.py # tasks.py import…

直方图变换——累计

#include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> int main() {// 图像获取及验证cv::Mat srcImage cv::imread("..\\images\\flower3.jpg");if( !srcImage.data ) return 1;//…

iOS开发经验总结,我的2019进阶之路!

4G改变了生活&#xff0c;抓住机会的人已经在这个社会有了立足之地&#xff0c;马上迎来5G的时代&#xff0c;你做好准备了吗&#xff01;对于即将迎来的5G时代&#xff0c;无疑会是音视频的又一个高潮&#xff01;那么作为程序员的我们&#xff0c;应该怎么样去迎接它呢~~ 改变…

【C++】C/C++ 中多态情形下的虚函数表查看方法

1.查看工具 找到VS2017命令提示符工具 选择“VS 2017的开发人员命令提示符” 点击该选项栏&#xff0c;弹出“VS 2017的开发人员命令提示符”窗口 cd 控制进入带查看类躲在的位置 使用命令&#xff1a;cl /d1 reportSingleClassLayoutXXX [filename]&#xff0c;XXX表示类名&…

PHP中session_register函数详解用法

语法: boolean session_register(string name);注册新的变量。返回值: 布尔值函数种类: 资料处理内容说明本函数在全域变量中增加一个变量到目前的 Session 之中。参数 name 即为欲加入的变量名。成功则返回 true 值。假如在头文件&#xff0c;开启session,即使用session_start…

Fedora 提出统一流程,弃用上千 Python 2 软件包更可控

开发四年只会写业务代码&#xff0c;分布式高并发都不会还做程序员&#xff1f; >>> Fedora 社区正在讨论弃用 Python 2 软件包的统一流程。 https://pythonclock.org Python 2 将于 2020 年 1 月 1 日正式退休&#xff0c;官方不再提供维护&#xff0c;当前倒计时不…

【C++】C++对象模型:对象内存布局详解(C#实例)

C对象模型&#xff1a;对象内存布局详解 0.前言 C对象的内存布局、虚表指针、虚基类指针解的探讨&#xff0c;参考。 1.何为C对象模型? 引用《深度探索C对象模型》这本书中的话&#xff1a; 有两个概念可以解释C对象模型&#xff1a; 语言中直接支持面向对象程序设计的部分…

Mybatis插件原理和PageHelper结合实战分页插件(七)

今天和大家分享下mybatis的一个分页插件PageHelper,在讲解PageHelper之前我们需要先了解下mybatis的插件原理。PageHelper的官方网站&#xff1a;https://github.com/pagehelper/Mybatis-PageHelper一、Plugin接口mybatis定义了一个插件接口org.apache.ibatis.plugin.Intercept…

直方图反向投影

#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include <iostream> using namespace cv; using namespace std; int main() {// 加载源图像并验证cv::Mat srcImage cv::imread("..\\images\\hand1.jpg&quo…

Java异常处理12条军规

摘要&#xff1a; 简单实用的建议。 原文&#xff1a;Java异常处理12条军规公众号&#xff1a;Spring源码解析Fundebug经授权转载&#xff0c;版权归原作者所有。 在Java语言中&#xff0c;异常从使用方式上可以分为两大类&#xff1a; CheckedExceptionUncheckedException在Ja…

【Smart_Point】C/C++ 中独占指针unique_ptr

1. 独占指针unique_ptr 目录 1. 独占指针unique_ptr 1.1 unique_ptr含义 1.2 C11特性 1.3 C14特性 1.1 unique_ptr含义 unique_ptr 是 C 11 提供的用于防止内存泄漏的智能指针中的一种实现&#xff0c;独享被管理对象指针所有权的智能指针。unique_ptr对象包装一个原始指…

ORA-01940无法删除当前已连接用户

原文地址&#xff1a;ORA-01940无法删除当前已连接用户作者&#xff1a;17361887941)查看用户的连接状况 select username,sid,serial# from v$session ------------------------------------------ 如下结果&#xff1a; username sid serial# ------…

距离变换扫描实现

#include <opencv2/imgproc/imgproc.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> // 计算欧式距离 float calcEuclideanDistance(int x1, int y1, int x2, int y2) {return sqrt(…

『扩欧简单运用』

扩展欧几里得算法 顾名思义&#xff0c;扩欧就是扩展欧几里得算法&#xff0c;那么我们先来简单地回顾一下这个经典数论算法。 对于形如\(axbyc\)的不定方程&#xff0c;扩展欧几里得算法可以在\(O(log_2alog_2b)\)的时间内找到该方程的一组特解&#xff0c;或辅助\(gcd\)判断该…

【Smart_Point】C/C++ 中共享指针 shared_ptr

1. 共享指针 shared_ptr 目录 1. 共享指针 shared_ptr 1.1 共享指针解决的问题&#xff1f; 1.2 创建 shared_ptr 对象 1.3 分离关联的原始指针 1.4 自定义删除器 Deleter 1.5 shared_ptr 相对于普通指针的优缺点 1.6 创建 shared_ptr 时注意事项 1.1 共享指针解决的问…

对数变换的三种实现方法

#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <iostream> using namespace cv; // 对数变换方法1 cv::Mat logTransform1(cv::Mat srcImage, int c) {// 输…

eclipse编辑窗口不见了(打开左边的java、xml文件,中间不会显示代码)

转自&#xff1a;https://blog.csdn.net/u012062810/article/details/46729779?utm_sourceblogxgwz4 1. windows-->reset Perspective 窗口-->重置窗口布局 2. windows -> new windows 新窗口 当时手贱了一下&#xff0c;结果…

js的执行机制

javascript的运行机制一直困扰在我&#xff0c;对其的运行机制也是一知半解&#xff0c;在看了https://juejin.im/post/59e85eebf265da430d571f89#heading-10这篇文章后&#xff0c;有种茅塞顿开的感觉,下面是原文内容&#xff1a; 认识javascript javascript是一门单线程语言&…

【Smart_Point】unique_ptr中独占指针使用MakeFrame

1. DFrame使用方法 std::unique_ptr<deptrum::Frame> MakeFrame(deptrum::FrameType frame_type,int width,int height,int bytes_per_pixel,void* data,uint64_t timestamp,int index,float temperature) {std::unique_ptr<deptrum::Frame> frame{std::make_uniq…

最大熵阈值分割

#include <opencv2/imgproc/imgproc.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace std; using namespace cv; // 计算当前的位置的能量熵 float caculateCurrentE…

php登录注册

php 登录注册 注册代码&#xff1a;register.php <style type"text/css">form{width:300px;background-color:#EEE0E5;margin-left:300px;margin-top:30px;padding:30px;}button{margin-top:20px;} </style> <form method"post"> <la…

【C++】C/C++ 中的单例模式

目录 part 0&#xff1a;单例模式3种经典的实现方式 Meyers Singleton Meyers Singleton版本二 Lazy Singleton Eager Singleton Testing part 1&#xff1a;C之单例模式 动机 实现一[线程不安全版本] 实现二[线程安全&#xff0c;锁的代价过高] 锁机制 实现三[双检…

计算图像波峰点

#include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream> #include <stdio.h> #include <iostream> #include <vector> using namespace std; using namespace cv; // 计算图像的波峰…

锁的算法,隔离级别的问题

锁的算法 InnoDB存储引擎有3中行锁的算法设计&#xff0c;分别是&#xff1a; Record Lock&#xff1a;单个行记录上的锁。Gap Lock&#xff1a;间隙锁&#xff0c;锁定一个范围&#xff0c;但不包含记录本身。Next-Key Lock&#xff1a;Gap LockRecord Lock&#xff0c;锁定一…

好程序员分享24个canvas基础知识小结

好程序员分享24个canvas基础知识小结&#xff0c;非常全面详尽&#xff0c;推荐给大家。 现把canvas的知识点总结如下&#xff0c;以便随时查阅。 1、填充矩形 fillRect(x,y,width,height); 2、绘制矩形边框 strokeRect(x,y,width,height); 3、擦除矩形 clearRect(x,y,width,he…

【leetcode】二叉树与经典问题

文章目录笔记leetcode [114. 二叉树展开为链表](https://leetcode-cn.com/problems/flatten-binary-tree-to-linked-list/)解法一: 后序遍历、递归leetcode [226. 翻转二叉树](https://leetcode-cn.com/problems/invert-binary-tree/)思路与算法复杂度分析leetcode [剑指 Offer…