如何在linux中控制鼠标移动?
发布时间:2021-01-17 14:47:36 所属栏目:Linux 来源:互联网
导读:我试图在 Linux中控制鼠标. Xlib似乎有效,但是当我尝试使用OpenCV时,它会继续返回: Resource temporarily unavailable 所以我决定写“/ dev / psaux”.代码如下: #include unistd.h#include string.h#include stdio.h#include errno.h#include s
|
我试图在 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,0x28,0xff};
int fp = open ("/dev/psaux",O_WRONLY);
if(!fp)printf("open error:%sn",strerror(errno));
for(int i = 0; i < 10; i++)
printf("write:%dtt%sn",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”. 有人可以帮我吗 如果这不是一个很好的方法来控制鼠标,有人可以告诉我另一个吗? 解决方法非常感谢@R ..提醒我一些其他方式,而不是/ dev / psaux 所以我试过/ dev / input / mouse *和/ dev / input / event * 通过使用 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 / input / event10可以工作.代码如下: #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:%sn",strerror(errno));
return -1;
}
memset(&event,sizeof(event));
memset(&event,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 – 我为用户/ .bashrc添加了别名,但是“sudo -u user
- linux – perf事件文档
- 使用云形成在linux-Ec2实例中自动挂载ebs卷?
- 允许的Linux密码字符列表
- Getting over the dangers of rm command in Linux---refer
- linux-kernel – do_IRQ中的中断向量和irq映射
- linux – 为什么将’script’重定向到/ dev / null /允许’
- LINUX学习:抓包工具tcpdump使用详解
- linux内核 – remap_pfn_range如何将内核内存重新映射到用户
- linux-kernel – 在strace中捕获vDSO
推荐文章
站长推荐
- linux 查看PHP,mysql,apache安装目录
- linux – 如何转义.gitconfig代理身份验证中的特
- qemu – “xx-softmmu”和“xx-linux-user”之间
- linux – 如何在* nix上查找/ grep目录名与“x”
- gnupg – gpg物理保护私钥文件
- linux – CentOS错误 – sudo:有效的uid不是0,s
- linux – cronjob计时是从它创建的那一刻开始还是
- linux – 如何通过puppet安全地禁用用户密码?
- Find command usage in Linux with excellent ex
- webserver – Angstrom Linux上的Web服务器根目录
热点阅读
