栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Linux中控制鼠标移动?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Linux中控制鼠标移动?

非常感谢@R .. 提醒我一些其他方式,而不是

/dev/psaux

于是,我就

/dev/input/mouse*
/dev/input/event*

通过使用

cat /proc/bus/input/devices

我得到这个:

I: Bus=0003 Vendor=0461 Product=4d81 Version=0111N: Name="USB Optical Mouse"P: Phys=usb-0000:00:1d.0-1/input0S: Sysfs=/devices/pci0000:00/0000:00:1d.0/usb6/6-1/6-1:1.0/input/input10U: Uniq=H: Handlers=mouse2 event10 B: EV=17B: KEY=70000 0 0 0 0 0 0 0 0B: REL=143B: 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, 0, sizeof(event));  memset(&event, 0, sizeof(event_end));  gettimeofday(&event.time, NULL);  event.type = EV_REL;  event.pre = REL_X;  event.value = 100;  gettimeofday(&event_end.time, NULL);  event_end.type = EV_SYN;  event_end.pre = 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;}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/408977.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号