您的位置:首页 > 移动开发 > Android开发

主机端模拟控制Android设备程序之鼠标模拟触屏

2015-07-03 10:56 736 查看
本次设计主要基于adb通信,速度比较慢。模拟鼠标事件用

input 命令常用的有

1、input text 《string》 输入文本

2、input keyevent (keycode number or name) 功能 按键

3、input tap X,Y 点击坐标

4、input swipe X1 ,Y1, X2,Y2 滑屏

5、screencap /data/ 截屏并保存到data目录

其中长时间点击功能不能实现。

一、计算一个函数从开始到结束所耗的时间,精确到微妙。所用的函数为

void test()

{

timeval t1,t2;

double timeuse;

gettimeofday(&t1,NULL);

foo(); //所要测试的功能

gettimeofday(&t2,NULL);

timeuse = t2.tv_sec - t1.tv_sec + (t2.tv_usec -t1.tv_usec)/1000000.0;

printf(“Use Time:%f\n”,timeuse);

} include sys/time.h

二、QT查找路径的对话框的实现

主要函数为QFileDialog()

test()

{

QString file = QFileDialog::getOpenFileName(this,NULL,”/home/user”);//reserch adb path

std::string str = file.toStdString();// Qstring to string

}

路径最终是str这个变量。#include QFileDialog

三、QT读写配置文件(ini文件)

写的过程

{

QSettings *configIniWrite = new QSettings(“adb_path.ini”, QSettings::IniFormat); //write to path file

configIniWrite->setValue(“/adb/path”, file);

delete configIniWrite;

}

读的过程

{

QSettings *configIniRead = new QSettings(“adb_path.ini”, QSettings::IniFormat);

QString pathResult = configIniRead->value(“/adb/path”).toString();//read adb path from adb_path.ini

std::string str = pathResult.toStdString();

delete configIniRead;

} include QSettings

四、调试debug

五、exec(“执行的命令”)是又起了一个进程,可以fork一个子进程去执行它,父进程继续。

一般用system(“ls”);

六、QT定时器

QTimer *timer=new QTimer(this);

connect(timer,SIGNAL(timeout()),this,SLOT(timeouts_slot()));//timeoutslot()为自定义槽

timer->start(500); //500ms

回调函数timeouts_slot()

{

}

每隔500ms执行一次回调函数,这样做会导致窗口界面卡顿。

采用线程去执行更好。

七、QT鼠标点击移动事件

鼠标单击事件

void MGraphicsView::mousePressEvent(QMouseEvent *e)

{

fromP1 =fromP2 = {((image->width())/480.00)*(e->x()-6)*2, ((image->height())/800.00)*(e->y()-6)*2};
qDebug("mousepressevent is %d  %d",fromP1.x,fromP1.y);
qDebug("image->width is %d",image->width());
//std::cout << " mousepressEvent is" << fromP1 << std::endl;


}

鼠标移动事件

void MGraphicsView::mousePressEvent(QMouseEvent *e)

{

fromP1 =fromP2 = {((image->width())/480.00)*(e->x()-6)*2, ((image->height())/800.00)*(e->y()-6)*2};
qDebug("mousepressevent is %d  %d",fromP1.x,fromP1.y);
qDebug("image->width is %d",image->width());
//std::cout << " mousepressEvent is" << fromP1 << std::endl;


}

鼠标释放事件

void MGraphicsView::mousePressEvent(QMouseEvent *e)

{

fromP1 =fromP2 = {((image->width())/480.00)*(e->x()-6)*2, ((image->height())/800.00)*(e->y()-6)*2};
qDebug("mousepressevent is %d  %d",fromP1.x,fromP1.y);
qDebug("image->width is %d",image->width());
//std::cout << " mousepressEvent is" << fromP1 << std::endl;


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: