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