【发布时间】:2011-12-02 06:54:01
【问题描述】:
我尝试在 Linux 中控制鼠标。 Xlib 似乎可以工作,但是当我尝试将它与 OpenCV 一起使用时,它会不断返回:
Resource temporarily unavailable
所以我决定写“/dev/psaux”。代码如下:
#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 cat /dev/psaux”并运行“my_psaux”。 但我只是什么都不做。 “/dev/psaux”中没有写入任何内容?
谁能帮帮我?
如果这不是控制鼠标的好方法,谁能告诉我另一个?
【问题讨论】:
-
除非您期望鼠标物理移动,否则我认为写入 PS/2 端口不是正确的做法...
-
感谢您的评论。我以前也是这么想的。然而,正如@R.. 所说,它更像是一个终端。换句话说,我们还没有接触到鼠标。
-
我怀疑,你听起来还是非常困惑...