博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android 按键精灵。C++编写。
阅读量:4326 次
发布时间:2019-06-06

本文共 2453 字,大约阅读时间需要 8 分钟。

可以记录屏幕键盘等传感器对系统的输入。

上一篇文章做的那个稍微有点复杂了,还需要把板子的输出拿回电脑处理再倒回去。这个就简单多了用法如下

usage:

event record /path/file1
event replay /path/file1

给我女友写的程序直接搬过来了,所以注释有些冗余。

"stdafx.h"

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct input_event { timeval time; __u16 type; __u16 code; __s32 value;};struct myinputevent:public input_event//继承了16字节的数据结构,添加了一个deviceID{ int deviceID;};

main.cpp

#include "stdafx.h"void record(char* filename);void replay(char* filename);int main(int argc, char *argv[]){    if(argc!=3 || (strcmp(argv[1],"record") & strcmp(argv[1],"replay")))    {        std::cout<<                "usage:"<
<< "event record /path/file1"<
<< "event replay /path/file1"<

 

replay.cpp

#include "stdafx.h"//#define DEBUGint timedif(timeval& a,timeval& b)//这是个计算时间差的函数,对于一个timeval的数据结构,前面4字节秒,后面4字节微秒//这个函数接受两个这样的结构,返回一个微秒单位的时间差{    return (b.tv_sec-a.tv_sec)*1000000+(b.tv_usec-a.tv_usec);}void replay(char* filename){    int fi = open(filename,O_RDONLY);    if(fi==-1)    {        std::cout<
<<" cannot be opened"<

record.cpp

 

#include "stdafx.h"#define DEBUGinline bool eventcmp(const myinputevent& a,const myinputevent& b)//这个比较函数为了之后排序用,因为两个自定义的数据结构,你用标准排序函数,排序肯定不知道你这俩结构应该怎么比大小//定义了我的数据结构之间如果做小于比较时,时间小就算小。//这样就可以采用标准排序函数对事件进行排序了。{    if(a.time.tv_sec
b.time.tv_sec) return 0; if(a.time.tv_usec
AllRecordedEvent;//这里有个数组,用来添加所有录制到的eventchar fn[200];void afterstop(int x)//按下ctrl+c和回车之后,录制停止,做数据整理和保存工作//主要是按时间顺序对事件排序,然后保存{#ifdef DEBUG std::cout<<"Recorded events:"<
<
code; my.type=p->type; my.value=p->value; my.time=p->time; my.deviceID=i; AllRecordedEvent.push_back(my); //这里可能难理解,buffer里存储了大量16字节的event,所以让指针p是数据结构指针,然后16字节16字节的挪动 //我有一个自己的数据结构叫myinputevent,比这个16字节来说,尾部添加了一个4字节的int,存储设备的event号 //你可以在stdafx.h中看到这些数据结构 //把那16字节的原封不动的放到我的数据结构中,再把我自己的设备号赋值,就完成了这一个事件的录制。 //然后就存储到AllRecordedEvent里面去。 } } } }}

 

转载于:https://www.cnblogs.com/zhangzheng/p/3261224.html

你可能感兴趣的文章
用 python 实现各种排序算法(转)
查看>>
在Sql Server上安装插件Sql Prompt
查看>>
Hibernate三大类查询总结
查看>>
软件测试第5次作业
查看>>
TypeScript完全解读(26课时)_9.TypeScript完全解读-TS中的类
查看>>
内置函数 集锦
查看>>
文成小盆友python-num6 -反射 ,常用模块
查看>>
Struts2.0中ActionInvocation使用
查看>>
使用samba实现linux与windows共享(测试成功)
查看>>
k8s 常用命令
查看>>
UnderWater+SDN论文之二
查看>>
jQuery.ajax() 设置 Headers 中的 Accept 内容
查看>>
[leetcode] Validate Binary Search Tree
查看>>
省选前的字符串抢救计划
查看>>
Math工具类的使用
查看>>
C++ 中头文件(.h)和源文件(.cc)的写法简述
查看>>
iOS 崩溃 问题 警告 错误2
查看>>
监听系统键盘的方法
查看>>
《DSP using MATLAB》Problem 7.25
查看>>
[连载]《C#通讯(串口和网络)框架的设计与实现》-1.通讯框架介绍
查看>>