如何控制在Linux鼠标移动? [英] How to control mouse movement in linux?
本文介绍了如何控制在Linux鼠标移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尽量控制在Linux下鼠标。 Xlib中似乎工作,但是当我尝试使用OpenCV的使用它,它会反复:
I try to control the mouse in Linux. Xlib seems to works, but when I try to use it with OpenCV, it keeps returning:
Resource temporarily unavailable
所以我决定写的/ dev / psaux。在code是如下:
So I decide to write "/dev/psaux". The code is as following:
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main() {
unsigned char a[5]={0, 0xff, 0, 0x28, 0xff};
int fp = open ("/dev/psaux", O_WRONLY);
if(!fp)printf("open error:%s\n", strerror(errno));
for(int i = 0; i < 10; i++)
printf("write:%d\t\t%s\n", write(fp, a, 5), strerror(errno));
close(fp);
return 0;
}
与编译:
gcc my_psaux.c -o my_psaux -std=gnu99 -g
运行并获得
$sudo ./my_psaux
write:5 Success
write:5 Success
write:5 Success
write:5 Success
write:5 Success
write:5 Success
write:5 Success
write:5 Success
write:5 Success
write:5 Success
但鼠标不动。然后我打开一个新的终端,输入sudo的猫的/ dev / psaux并运行my_psaux。
但我只是猫什么。 没有写入的/ dev / psaux?
谁能帮助我?
如果这不是控制鼠标的好方法,任何人都可以告诉我另外一个?
If this is not a good method to control the mouse, could anyone tell me another one?
推荐答案
十分感谢@R ..
提醒我一些其他的方式,而不是的/ dev / psaux
所以,我想的/ dev /输入/鼠标*
和的/ dev /输入/事件*
通过使用
cat /proc/bus/input/devices
我得到这样的:
I: Bus=0003 Vendor=0461 Product=4d81 Version=0111
N: Name="USB Optical Mouse"
P: Phys=usb-0000:00:1d.0-1/input0
S: Sysfs=/devices/pci0000:00/0000:00:1d.0/usb6/6-1/6-1:1.0/input/input10
U: Uniq=
H: Handlers=mouse2 event10
B: EV=17
B: KEY=70000 0 0 0 0 0 0 0 0
B: REL=143
B: MSC=10
经过测试,只有的/ dev /输入/ event10
的作品。在code是如下:
After testing, only /dev/input/event10
works. The code is as following:
#include <stdio.h>
#include <unistd.h>
#include <linux/input.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
int main() {
struct input_event event, event_end;
int fd = open("/dev/input/event10", O_RDWR);
if (fd < 0) {
printf("Errro open mouse:%s\n", strerror(errno));
return -1;
}
memset(&event, 0, sizeof(event));
memset(&event, 0, sizeof(event_end));
gettimeofday(&event.time, NULL);
event.type = EV_REL;
event.code = REL_X;
event.value = 100;
gettimeofday(&event_end.time, NULL);
event_end.type = EV_SYN;
event_end.code = SYN_REPORT;
event_end.value = 0;
for (int i=0; i<5; i++) {
write(fd, &event, sizeof(event));// Move the mouse
write(fd, &event_end, sizeof(event_end));// Show move
sleep(1);// wait
}
close(fd);
return 0;
}
这篇关于如何控制在Linux鼠标移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文