最近需要寫這個(gè)程序。網(wǎng)上沒看著太好的,還是自己動(dòng)手寫一個(gè)。大概的思想是通過getevent獲得屏幕移動(dòng)的數(shù)據(jù),將數(shù)據(jù)以2進(jìn)制格式保存,用c語(yǔ)言讀取后寫入到屏幕。

首先用android提供的getevent進(jìn)行事件記錄,直接輸入getevent可以看到你的屏幕是哪個(gè)event。

創(chuàng)新互聯(lián)2013年開創(chuàng)至今,先為梅江等服務(wù)建站,梅江等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為梅江企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
然后getevent -t /dev/input/eventX,輸入完之后去操作屏幕,錄入你想錄的操作,輸出的格式是
時(shí)間 數(shù)字 數(shù)字 數(shù)字
不同的板子的時(shí)間這一塊不太一樣,要具體問題具體分析。一般來(lái)說是形如[10.123]。這里不能直接轉(zhuǎn)換成sendevent的腳本,因?yàn)閟endevent中,那三個(gè)數(shù)字通過參數(shù)進(jìn)入,需要用atoi轉(zhuǎn)換成整數(shù)寫入設(shè)備,而event在數(shù)秒內(nèi)就可以有數(shù)百個(gè),這樣的字符串轉(zhuǎn)整數(shù)通常是手機(jī)平臺(tái)不能流暢完成的。所以用下面一段python3代碼:
import struct
time0=0
rectimes=0
lastrec=0
with open("e:\ev1.txt",'r') as f, open("e:\rec2.touch",'wb') as wf, open("e:\rec2.index",'wb') as id:
for line in f:
line=line.split(' ')
time1=int(float(line[0][1:-1])*1000000)
print(line)
if (time1-time0)>0:
#write sleeptime, and readtimes
if rectimes==0:
id.write(struct.pack('ii',0,rectimes-lastrec))
else:
id.write(struct.pack('ii',time1-time0,rectimes-lastrec))
lastrec=rectimes
time0=time1
rectimes+=1 #python -> C struct
# 2byte __u16 type
# 2byte __u16 code
# 4byte __s32 value wf.write(struct.pack("HHI",int(line[1],16),int(line[2],16),int(line[3].strip(),16)))
然后寫了一段C代碼在板子上跑,這里要交叉編譯
#include
#include
#include
#include
#include
#include
#include
#include
//#include // this does not compile
#include
#include
struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
};
int main(int argc, char *argv[])
{
int fd,fi,ft;
int ret;
int version;
struct input_event event;
if(argc != 3) {
fprintf(stderr, "use: %s device filename
", argv[0]);
return 1;
}
char TouchFile[40],IndexFile[40];
strcpy(TouchFile,argv[2]);
strcpy(IndexFile,argv[2]);
strcat(TouchFile,".touch");
strcat(IndexFile,".index");
ft = open(TouchFile,O_RDONLY);
fi = open(IndexFile,O_RDONLY);
fd = open(argv[1], O_RDWR);
while(1)
{
struct input_event event;
memset(&event, 0, sizeof(event));
int sleeptime;
if(read(fi,(char*)&sleeptime,4)==0)
{
while(read(ft,&(event.type),8))
{
write(fd, &event, sizeof(event));
}
return 0;
}
// printf("sleeptime:%d
",sleeptime);
int readtimes;
read(fi,(char*)&readtimes,4);
// printf("readtimes:%d
",readtimes);
int i=0;
char buffer[8];
for(;i
當(dāng)前文章:android按鍵精靈,通過getevent記錄后發(fā)出-創(chuàng)新互聯(lián)
新聞來(lái)源:http://weahome.cn/article/cdijss.html