Jpp
Functions
JKeypress.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include "JSystem/JKeypress.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

Example program to test key board pressings (class JSYSTEM::JKeypress).

Author
mdejong

Definition in file JKeypress.cc.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 16 of file JKeypress.cc.

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 }
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std
Definition: jaanetDictionary.h:36
FATAL
#define FATAL(A)
Definition: JMessage.hh:67