-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTouchInputEmulator.cpp
125 lines (115 loc) · 4.31 KB
/
TouchInputEmulator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <QPoint>
#include <QDebug>
#include "TouchInputEmulator.h"
TouchInputEmulator::TouchInputEmulator() : update_(false),
singleTouch_(false)
{
if (TRUE == InitializeTouchInjection(MAX_NB_CONTACT_POINTS, TOUCH_FEEDBACK_DEFAULT)) {
ready_ = true;
} else {
qDebug() << "error in InitializeTouchInjection " << GetLastError();
}
}
void TouchInputEmulator::initContact(const QPoint &pt, int id)
{
memset(contact_+id, 0, sizeof(POINTER_TOUCH_INFO));
contact_[id].pointerInfo.pointerType = PT_TOUCH;
contact_[id].pointerInfo.pointerId = id; //contact index
contact_[id].pointerInfo.ptPixelLocation.y = pt.y(); // Y co-ordinate of touch on screen
contact_[id].pointerInfo.ptPixelLocation.x = pt.x(); // X co-ordinate of touch on screen
contact_[id].touchFlags = TOUCH_FLAG_NONE;
contact_[id].touchMask = TOUCH_MASK_CONTACTAREA | TOUCH_MASK_ORIENTATION | TOUCH_MASK_PRESSURE;
contact_[id].orientation = 90; // Orientation of 90 means touching perpendicular to screen.
contact_[id].pressure = 32000;
// defining contact area (4 x 4 pixels)
contact_[id].rcContact.top = contact_[id].pointerInfo.ptPixelLocation.y - 2;
contact_[id].rcContact.bottom = contact_[id].pointerInfo.ptPixelLocation.y + 2;
contact_[id].rcContact.left = contact_[id].pointerInfo.ptPixelLocation.x - 2;
contact_[id].rcContact.right = contact_[id].pointerInfo.ptPixelLocation.x + 2;
}
int TouchInputEmulator::touchDown(const QPoint &pt)
{
if (!ready_) { // Here number of contact point is declared as 1.
qDebug() << "Error in InitializeTouchInjection";
return EXIT_FAILURE;
}
initContact(pt, 0);
contact_[0].pointerInfo.pointerFlags = POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;
if (update_) {
contact_[0].pointerInfo.pointerFlags |= POINTER_FLAG_UPDATE;
} else {
contact_[0].pointerInfo.pointerFlags |= POINTER_FLAG_DOWN;
update_ = true;
}
if (FALSE == InjectTouchInput(1, contact_)) { // Injecting the touch down on screen
qDebug() << "Error in InjectTouchInput " << GetLastError();
return EXIT_FAILURE;
}
singleTouch_ = true;
qDebug() << "single touch down at" << pt;
return EXIT_SUCCESS;
}
int TouchInputEmulator::touchUp(const QPoint &pt)
{
if (!ready_) { // Here number of contact point is declared as 1.
qDebug() << "Error in InitializeTouchInjection";
return EXIT_FAILURE;
}
initContact(pt, 0);
contact_[0].pointerInfo.pointerFlags = POINTER_FLAG_UP;
update_ = false;
if (FALSE == InjectTouchInput(1, contact_)) { // Injecting the touch up from screen
qDebug() << "Error in InjectTouchInput " << GetLastError();
return EXIT_FAILURE;
}
singleTouch_ = false;
qDebug() << "single touch up at" << pt;
return EXIT_SUCCESS;
}
int TouchInputEmulator::touchDown(const QPoint &pt1, const QPoint &pt2)
{
if (!ready_) { // Here number of contact point is declared as 1.
qDebug() << "Error in InitializeTouchInjection";
return EXIT_FAILURE;
}
if (singleTouch_) {
touchDown(pt1);
touchUp(pt1);//needed before using double point touch gesture
}
initContact(pt1, 0);
initContact(pt2, 1);
for (int i = 0; i < MAX_NB_CONTACT_POINTS; ++i) {
contact_[i].pointerInfo.pointerFlags = POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;
if (update_) {
contact_[i].pointerInfo.pointerFlags |= POINTER_FLAG_UPDATE;
} else {
contact_[i].pointerInfo.pointerFlags |= POINTER_FLAG_DOWN;
if ((MAX_NB_CONTACT_POINTS-1) == i) update_ = true;
}
}
if (FALSE == InjectTouchInput(2, contact_)) { // Injecting the touch down from screen
qDebug() << "Error in InjectTouchInput " << GetLastError();
return EXIT_FAILURE;
}
qDebug() << "double touch down at" << pt1 << "," << pt2;
return EXIT_SUCCESS;
}
int TouchInputEmulator::touchUp(const QPoint &pt1, const QPoint &pt2)
{
if (!ready_) { // Here number of contact point is declared as 1.
qDebug() << "Error in InitializeTouchInjection";
return EXIT_FAILURE;
}
initContact(pt1, 0);
initContact(pt2, 1);
for (int i = 0; i < 2; ++i) {
contact_[i].pointerInfo.pointerFlags = POINTER_FLAG_UP;
}
update_ = false;
if (FALSE == InjectTouchInput(2, contact_)) { // Injecting the touch up from screen
qDebug() << "Error in InjectTouchInput " << GetLastError();
return EXIT_FAILURE;
}
qDebug() << "double touch up at" << pt1 << "," << pt2;
return EXIT_SUCCESS;
}