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