Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JKeypress.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4
6#include "Jeep/JParser.hh"
7#include "Jeep/JMessage.hh"
8
9
10/**
11 * \file
12 *
13 * Example program to test key board pressings (class JSYSTEM::JKeypress).
14 * \author mdejong
15 */
16int main(int argc, char* argv[])
17{
18 using namespace std;
19
20 bool echo;
21 int timeout_us;
22
23 try {
24
25 JParser<> zap("Example program to test key board pressings.");
26
27 zap['c'] = make_field(echo);
28 zap['t'] = make_field(timeout_us) = 1000;
29
30 zap(argc, argv);
31 }
32 catch(const exception &error) {
33 FATAL(error.what() << endl);
34 }
35
36
37 using namespace JPP;
38
39 if (true) {
40
41 cout << "> " << flush;
42
43 int c = JKeypress(echo).get();
44
45 cout << endl << "return <" << (char) c << ">" << endl;
46 }
47
48 if (true) {
49
50 JKeypress keypress(false);
51
52 int c = (int) '?';
53
54 for (int i = 0; i != 10000; ++i) {
55
56 cout << setw(5) << i << flush << '\r';
57
58 if (keypress.timeout(timeout_us)) {
59 c = keypress.get();
60 break;
61 }
62 }
63
64 cout << endl << "return <" << (char) c << ">" << endl;
65 }
66}
int main(int argc, char *argv[])
Definition JKeypress.cc:16
Keyboard settings for unbuffered input.
General purpose messaging.
#define FATAL(A)
Definition JMessage.hh:67
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse command line options.
Definition JParser.hh:1698
Enable unbuffered terminal input.
Definition JKeypress.hh:32
bool timeout(JTimeval timeout)
Timeout method.
Definition JKeypress.hh:92
char get()
Get single character.
Definition JKeypress.hh:74
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).