-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyListener.cpp
More file actions
56 lines (42 loc) · 1.04 KB
/
KeyListener.cpp
File metadata and controls
56 lines (42 loc) · 1.04 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
#include "KeyListener.hpp"
KeyListener::KeyListener(vector<int> key_codes, Bugger * bugger)
{
//ctor
_bugger = bugger;
_key_codes = key_codes;
_class_name = __func__;
}
void KeyListener::listen(){
this->_is_listening = true;
this->_bugger->trace("listening!", this->_class_name);
do {
int key = this->keypress();
for(int i=0; i < this->_key_codes.size(); ++i){
cout << "looping \n" << this->_key_codes[i] << endl;
if(key == this->_key_codes[i]){
cout << "valid command" << endl;
this->stopListen();
break;
}
}
this->_is_listening = false;
cout << key << "\n";
} while (this->_is_listening);
}
int KeyListener::keypress() {
system ("/bin/stty raw");
int c;
system("/bin/stty -echo");
c = getc(stdin);
system("/bin/stty echo");
system ("/bin/stty cooked");
return c;
}
void KeyListener::stopListen(){
cout << "stopListen" << endl;
this->_is_listening = false;
}
KeyListener::~KeyListener()
{
//dtor
}