| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2294 人关注过本帖
标题:linux下一段模拟鼠标操作的代码,但编译时出现这个问题.
只看楼主 加入收藏
b1592187525
Rank: 1
等 级:新手上路
帖 子:86
专家分:4
注 册:2017-2-15
结帖率:90.32%
收藏
 问题点数:0 回复次数:0 
linux下一段模拟鼠标操作的代码,但编译时出现这个问题.
这段代码能否模拟鼠标定时左键点击操作,比如在屏幕上定位某点鼠标坐标,然后每隔一段时间程序自动执行对该点的左键点击操作?
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
/*
*模拟鼠标轨迹球
*/
void simulate_mouse(int fd, int value)
{
struct input_event event;
memset(&event, 0, sizeof(event));
gettimeofday(&event.time, NULL);
event.type = EV_REL;
event.code = REL_X;//鼠标x轴方向
event.value = value;//x轴方向相对位移
write(fd, &event, sizeof(event));//写入
event.type = EV_REL;
event.code = REL_Y;//鼠标y轴方向
event.value = value;//y轴方向相对位移
write(fd, &event, sizeof(event));//写入
event.type = EV_SYN;//同步
event.code = SYN_REPORT;
event.value = 0;
write(fd, &event, sizeof(event));
}
/*
*模拟鼠标单击,先按下后释放
*/
void simulate_mouse_click(int fd,int value){
struct input_event event;
memset(&event, 0, sizeof(event));
gettimeofday(&event.time, NULL);
event.type = EV_KEY;
event.code = value;
event.value = 1;
if(write(fd,&event,sizeof(event)) < 0){
LOGE("mouse key write error.\n");
}
event.type = EV_SYN;
event.code = SYN_REPORT;
event.value = 0;
write(fd, &event, sizeof(event));
event.type = EV_KEY;
event.code = value;
event.value = 0;
if(write(fd,&event,sizeof(event)) < 0){
LOGE("mouse key write error.\n");
}
event.type = EV_SYN;
event.code = SYN_REPORT;
event.value = 0;
write(fd, &event, sizeof(event));
return;
}
int main(void)
{
int fd_mouse;
int value = 0;
fd_mouse = open("/dev/input/event2", O_RDWR);//打开设备节点
if (fd_mouse <= 0)
{
printf("error open mouse\n");
return -2;
}
while (1)
{
value = 0;
for (value = 0; value < 10; value++)
{
simulate_mouse(fd_mouse, value);
usleep(20*1000);
}
getchar();
for (value = 0; value > -10; value--)
{
simulate_mouse(fd_mouse, value);
usleep(20*1000);
}
getchar();
}
simulate_mouse_click(fd_mouse,BTN_LEFT);//点击鼠标左键
close(fd_mouse);
return 0;
}
保存为qqq.c文件。
linux下编译后产生了这个问题:该如何解决?
qqq.c: In function ?simulate_mouse_click?:

qqq.c:43:1: warning: implicit declaration of function ?LOGE? [-Wimplicit-function-declaration]

LOGE("mouse key write error.\n");

^

/tmp/ccWjXPhk.o: In function `simulate_mouse_click':

qqq.c:(.text+0x152): undefined reference to `LOGE'

qqq.c:(.text+0x1b9): undefined reference to `LOGE'

collect2: error: ld returned 1 exit status
搜索更多相关主题的帖子: 鼠标 include value event write 
2018-05-07 20:06
快速回复:linux下一段模拟鼠标操作的代码,但编译时出现这个问题.
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017105 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved