#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>#include <sys/mman.h>//#define DBG_PRINTF(...)
#define DBG_PRINTF printfchar *command="cat /proc/bus/input/devices > " ;
char *file_path="./";
char *file_buff;int number;
int find_event()
{int iFd;FILE *tFp;struct stat tStat;char *sub_buff="Handlers=mouse1"; /* according to mouse name find event number*/char *buff;tFp=fopen(file_path,"r+"); /* check if file */if(NULL!=tFp){fclose(tFp);system("");}system(command);/* 打开文件 */tFp = fopen(file_path, "r+");if (tFp == NULL){DBG_PRINTF("can't open %sn", file_path);return -1;}iFd = fileno(tFp);fstat(iFd, &tStat);/* mmap the file to mem */file_buff = (unsigned char *)mmap(NULL , tStat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, iFd, 0);if (file_buff== (unsigned char *)-1){DBG_PRINTF("mmap error!n");return -1;}buff=strstr(file_buff,sub_buff);/* in the mem file_buff find sub_buff name */if(NULL==buff){DBG_PRINTF("can't find %sn",sub_buff);munmap(file_buff, tStat.st_size);return -1;}number=*(buff+strlen(sub_buff)+6);/* 6== event */munmap(file_buff, tStat.st_size);fclose(tFp);return 0;}int main(int argc, char **argv)
{find_event();DBG_PRINTF("event%dn",number-'0');return 0;
}
本文发布于:2024-02-04 18:13:49,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170713413758170.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |