linux 鼠标点击,linux下使用xlib模拟鼠标移动和点击
/* ref: http://www.ishiboo.com/~danny/Projects/xwarppointer/ */
#include
#include
//头文件
#include
#include
#include
#include
//全局变量
Display *display;
Window root;
//初始化
void init()
{
if ((display = XOpenDisplay(NULL)) == NULL) {
fprintf(stderr, "Cannot open local X-display.\n");
return;
}
root = DefaultRootWindow(display);
}
//得到坐标
void GetCursorPos(int &x,int &y)
{
int tmp;unsigned int tmp2;
Window fromroot, tmpwin;
XQueryPointer(display, root, &fromroot, &tmpwin, &x, &y, &tmp, &tmp, &tmp2);
}
//设置坐标
void SetCursorPos(int x,int y)
{
int tmp;
XWarpPointer(display, None, root, 0, 0, 0, 0, x, y);
XFlush(display);
}
//模拟点击
/* http://www.linuxquestions.org/questions/programming-9/simulating-a-mouse-click-594576/ */
void mouseClick(int button)
{
Display *display = XOpenDisplay(NULL);
XEvent event;
if(display == NULL)
{
printf("Errore nell'apertura del Display !!!\n");
return;
}
memset(&event, 0x00, sizeof(event));
event.type = ButtonPress;
event.xbutton.button = button;
event.xbutton.same_screen = True;
XQueryPointer(display, RootWindow(display, DefaultScreen(display)), &event.xbutton.root, &event.xbutton.window, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);
event.xbutton.subwindow = event.xbutton.window;
while(event.xbutton.subwindow)
{
event.xbutton.window = event.xbutton.subwindow;
XQueryPointer(display, event.xbutton.window, &event.xbutton.root, &event.xbutton.subwindow, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);
}
if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) printf("Errore nell'invio dell'evento !!!\n");
XFlush(display);
usleep(100000);
event.type = ButtonRelease;
event.xbutton.state = 0x100;
if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) printf("Errore nell'invio dell'evento !!!\n");
XFlush(display);
XCloseDisplay(display);
}
int main()
{
init();
int x,y;
GetCursorPos(x,y);
printf("%d %d\n",x,y);
SetCursorPos(0,0);
XCloseDisplay(display);
mouseClick(Button1);
return 0;
}
linux 鼠标点击,linux下使用xlib模拟鼠标移动和点击相关推荐
- Delphi下利用WinIo模拟鼠标键盘详解
本文最早在编程论坛上发表,文章地址:http://programbbs.com/bbs/view12-17207-1.htm,相关文件可以在上述地址的页面中下载.转载时请注明出处. 前言 一日发现Se ...
- java 回车 按钮事件,java--键盘事件类,按下回车则模拟鼠标
import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.JButton; import ...
- C# 模拟鼠标移动和点击(转载)
本文转载自: C# 模拟鼠标移动和点击_biyusr的专栏-CSDN博客 https://blog.csdn.net/biyusr/article/details/108376195 我们需要用到的m ...
- Delphi下利用SendInput模拟鼠标键盘
前言 发了一篇<Delphi下利用WinIo模拟鼠标键盘详解>(http://programbbs.com/bbs/view12-17207-1.htm),再发一个利用SendInput模 ...
- C# 模拟鼠标移动与点击
我们需要用到的mouse_event函数,位于user32.dll这个库文件里面,所以我们要先声明引用. [System.Runtime.InteropServices.DllImport(" ...
- C# Win32API 模拟鼠标移动及点击事件
这个函数在user32.dll这个库文件里面.我们可以在C:\WINDOWS\system32(XP系统)这个目录下找到这个文件,他是系统自带的. 我们以C#直接调用这个文件中的API为例子来说下怎么 ...
- C# 模拟鼠标移动和点击
我们需要用到的mouse_event函数,位于user32.dll这个库文件里面,所以我们要先声明引用. [System.Runtime.InteropServices.DllImport(" ...
- python 捕获鼠标点击事件_Python捕捉和模拟鼠标事件的方法
本文实例讲述了Python捕捉和模拟鼠标事件的方法.分享给大家供大家参考.具体分析如下: 这个假期玩了不少galgame,不过有些很老的游戏没有自动运行模式,点击鼠标又太伤按键了,于是想把滚动鼠标滚轮 ...
- python 模拟鼠标,键盘点击
信息爆炸 '''消息轰炸模拟鼠标和键盘敲击'''import time from pynput.keyboard import Controller as key_col from pynput.mo ...
最新文章
- 2022-2028年中国辉石行业市场全景调查及发展前景分析报告
- [k8s] 重新加入master节点
- hdu 5419(数学期望)
- ES6 各浏览器支持情况
- codeforces 266B-C语言解题报告
- 美团点评酒旅数据仓库建设实践
- 数学家比10个师更有威力?
- Google Protobuf 开发指南
- maven添加tomcat插件
- 详细对比9门主流编程语言
- scala里集合排序函数的使用
- spring3.0注解定时任务配置及说明
- 线性系统理论3 状态空间描述 方框图
- ROS Bridge 笔记(02)— carla_ros_bridge 功能包(准备 ROS环境、运行 ROS Bridge、配置 CARLA 参数、同步模式下使用 ROS Bridge、主车辆控制)
- 逻辑思维题总结与例题分析
- C# Web页面打印网页
- doodoo.js快速入门教程
- 在Android Studio中的混淆debug与release
- 微信小程序:工具配置 project.config.json
- 塔多漫画一直维护服务器,塔多漫画
热门文章
- java ip正则表达式_java如何用正则表达式判断IP格式
- 姨妈来了照样当夏日C位 TAMPAX丹碧丝联手聚划算欢乐谷动感开浪
- EUROCAT-X的OASYS监控系统
- mysql查询前5条记录_各个数据库中,查询前n条记录的方法
- 基于java+springboot+mybatis+vue+elementui的体质测试数据分析
- vs2005 tools office -excel
- 十个最为戳心测试/开程序员笑话,念茫茫人海,该如何寻觅?
- 保险行业数字化转型必须知道的 10 项「黑科技」
- Deepchem构建基于分子指纹的神经网络模型
- IDEA - PlantUML插件安装