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
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
", strerror(errno));
for(int i = 0; i < 10; i++)
printf("write:%d%s
", write(fp, a, 5), strerror(errno));
close(fp);
return 0;
}
Compile it with:
gcc my_psaux.c -o my_psaux -std=gnu99 -g
Run and get
$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
However the mouse doesn't move. Then I open a new terminal, type in "sudo cat /dev/psaux" and run "my_psaux".
But I just cat nothing. Nothing is written into "/dev/psaux" ?
Could anyone help me?
If this is not a good method to control the mouse, could anyone tell me another one?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…