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