Xlib鼠标移动和点击
来源:互联网 发布:滑轮组实验数据 编辑:程序博客网 时间:2024/06/05 19:01
#include <stdio.h>
#include <string.h>
//头文件
#include <unistd.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
//全局变量
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;
}
0 0
- Xlib鼠标移动和点击
- linux下使用xlib模拟鼠标移动和点击【转贴】
- 模拟鼠标点击和移动
- 模拟鼠标移动和点击
- opencv 检测鼠标的点击和移动
- MATLAB实现控制鼠标移动和点击
- 鼠标移动/点击事件
- UGUI鼠标点击移动
- 鼠标点击移动
- 桌面移动鼠标点击和窗口切换小外挂
- Unity鼠标控制物体360°旋转和点击移动
- vs2005 鼠标点击事件移动
- 鼠标点击控制角色移动
- duilib 鼠标点击窗体移动
- 小球跟随鼠标点击移动
- 程序模拟鼠标移动、点击
- 鼠标点击,移动,释放事件
- 自动点击鼠标,非手动移动鼠标
- 【android学习】设置TextView顶部图片
- 《Windows API》遍历卷
- ViewFilpper实现文字LED显示效果
- 努力提高自己
- RGB颜色查询对照表
- Xlib鼠标移动和点击
- Html5 百度地图定位
- 邮票问题
- seq a
- 多线程编程之临界区的应用
- Android sdk更新,源码下载等
- window对象属性查询器
- Ecahrts 3.19 饼图 ajax+ashx+json
- Android ViewPager切换之PageTransformer接口中transformPage方法position参数使用详解