-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyPresser.cpp
More file actions
79 lines (73 loc) · 1.37 KB
/
KeyPresser.cpp
File metadata and controls
79 lines (73 loc) · 1.37 KB
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
#include "KeyPresser.h"
#include <iostream>
KeyPresser::KeyPresser()
{
xdo_instance = xdo_new(NULL);
q = w = o = p = false;
}
KeyPresser::~KeyPresser()
{
qwopPush("");
xdo_free(xdo_instance);
}
void KeyPresser::focus(int x,int y)
{
xdo_move_mouse(xdo_instance,x,y,0);
xdo_click_window(xdo_instance,CURRENTWINDOW,1);
}
void KeyPresser::enterText(const char* text)
{
xdo_enter_text_window(xdo_instance,CURRENTWINDOW,text,12000);
}
void KeyPresser::keyDown(const char *key)
{
xdo_send_keysequence_window_down(xdo_instance,CURRENTWINDOW,key,12000);
// std::cerr<<"keydown "<<key<<std::endl;
//usleep(10000);
}
void KeyPresser::keyUp(const char *key)
{
xdo_send_keysequence_window_up(xdo_instance,CURRENTWINDOW,key,12000);
//usleep(10000);
}
void KeyPresser::qwopPush(const char * keys)
{
//return;
bool _q = false;
bool _w = false;
bool _o = false;
bool _p = false;
const char *keyp =keys;
while(*keyp != 0) {
if(*keyp == 'q')
_q = true;
if(*keyp == 'w')
_w = true;
if(*keyp == 'o')
_o = true;
if(*keyp == 'p')
_p = true;
keyp++;
}
if(q && !_q)
keyUp("q");
if(_q && !q)
keyDown("q");
if(w && !_w)
keyUp("w");
if(_w && !w)
keyDown("w");
if(o && !_o)
keyUp("o");
if(_o && !o)
keyDown("o");
if(p && !_p)
keyUp("p");
if(_p && !p)
keyDown("p");
q = _q;
w = _w;
o = _o;
p = _p;
//std::cerr <<q<<w<<o<<p<<std::endl;
}