-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadKeyboard_test.cpp
73 lines (49 loc) · 1.34 KB
/
ReadKeyboard_test.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
/// ReadKeyboard_test.cpp
/**
Test of the utilities::ReadKeyboard class.
*/
#ifdef READ_KEYBOARD_TEST
#include <iostream>
#include <vector>
#include <ctime>
#include "ReadKeyboard.h"
int ReadKeyboard_test()
{
using namespace std;
using namespace utilities;
int key = 0;
int nKeyStrokes = 0;
struct timespec sleepTime;
struct timespec returnTime;
sleepTime.tv_sec = 0;
sleepTime.tv_nsec = 1000000;
cout << "ReadKeyboard test, nonblocking mode: press 'q' to exit... " << flush;
{ // In this block, read the keyboard in a non blocking way
ReadKeyboard rdKb;
while(key != 'q')
{
key = rdKb.Get();
if(key) ++nKeyStrokes;
cout << char(key) << flush;
// Meaninful block of code:
nanosleep(&sleepTime, &returnTime);
cout << "." << flush;
}
cout << "\n\nDone. " << nKeyStrokes << " keys pressed.\n\n";
}
cout << "ReadKeyboard test, blocking mode: press any key... " << flush;
{ // In this block, read the keyboard in blocking mode //+B this does not work!
ReadKeyboard rdKb;
rdKb.Blocking();
key = rdKb.Get();
cout << char(key) << endl;
}
cout << "ReadKeyboard test, blocking mode 2: press any key... " << flush;
{ // In this block, read the keyboard in blocking mode
ReadKeyboard rdKb;
key = rdKb.Getch();
cout << char(key) << endl;
}
return 0;
}
#endif // READ_KEYBOARD_TEST