Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
tutorial-event-keyboard.cpp
1 #include <visp3/gui/vpDisplayOpenCV.h>
3 #include <visp3/gui/vpDisplayX.h>
4 #include <visp3/gui/vpDisplayGTK.h>
5 #include <visp3/gui/vpDisplayGDI.h>
6 #include <visp3/gui/vpDisplayD3D.h>
7 
8 int main()
9 {
10  vpImage<unsigned char> I(240, 320); // Create a black image
11 #if defined(VISP_HAVE_X11)
12  vpDisplay *d = new vpDisplayX;
13 #elif defined(VISP_HAVE_GTK)
14  vpDisplay *d = new vpDisplayGTK;
15 #elif defined(VISP_HAVE_GDI)
16  vpDisplay *d = new vpDisplayGDI;
17 #elif defined(VISP_HAVE_D3D9)
18  vpDisplay *d = new vpDisplayD3D;
19 #elif defined(VISP_HAVE_OPENCV)
20  vpDisplay *d = new vpDisplayOpenCV;
21 #else
22  std::cout << "Sorry, no video device is available" << std::endl;
23  return -1;
24 #endif
25  // Initialize the display with the image I. Display and image are
26  // now link together.
27 #ifdef VISP_HAVE_DISPLAY
28  d->init(I);
29 #endif
30  // Set the display background with image I content
32  // Flush the foreground and background display
34  // Wait for keyboard event
35  std::cout << "Waiting a keyboard event..." << std::endl;
37  std::cout << "A keyboard event was detected" << std::endl;
38  // Non blocking keyboard event loop
39  int cpt_event = 0;
40  char key[10];
41  std::cout << "Enter a non blocking keyboard event detection loop..." << std::endl;
42  do {
43  bool event = vpDisplay::getKeyboardEvent(I, &key[0], false);
44  if (event) {
45  std::cout << "Key detected: " << key << std::endl;
46  cpt_event ++;
47  }
48  vpTime::wait(5); // wait 5 ms
49  } while(cpt_event < 5);
50 #ifdef VISP_HAVE_DISPLAY
51  delete d;
52 #endif
53 }
VISP_EXPORT int wait(double t0, double t)
Definition: vpTime.cpp:173
Class that defines generic functionnalities for display.
Definition: vpDisplay.h:171
Display for windows using GDI (available on any windows 32 platform).
Definition: vpDisplayGDI.h:128
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Definition: vpDisplayX.h:150
static void flush(const vpImage< unsigned char > &I)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
Definition: vpDisplayD3D.h:106
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Definition: vpDisplayGTK.h:137
static bool getKeyboardEvent(const vpImage< unsigned char > &I, bool blocking=true)