Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-event-keyboard.cpp
1
2#include <visp3/core/vpConfig.h>
3#include <visp3/gui/vpDisplayFactory.h>
4
5#ifdef ENABLE_VISP_NAMESPACE
6using namespace VISP_NAMESPACE_NAME;
7#endif
8
9int main()
10{
11#if defined(VISP_HAVE_DISPLAY)
12 vpImage<unsigned char> I(240, 320); // Create a black image
13
14 // Initialize the display with the image I. Display and image are now linked together
15#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
16 std::shared_ptr<vpDisplay> d = vpDisplayFactory::createDisplay(I, -1, -1, "Keyboard event example", vpDisplay::SCALE_AUTO);
17#else
18 vpDisplay *d = vpDisplayFactory::allocateDisplay(I, -1, -1, "Keyboard event example", vpDisplay::SCALE_AUTO);
19#endif
20
21 // Set the display background with image I content
23 // Flush the foreground and background display
25 // Wait for keyboard event
26 std::cout << "Waiting a keyboard event..." << std::endl;
28 std::cout << "A keyboard event was detected" << std::endl;
29 // Non blocking keyboard event loop
30 int cpt_event = 0;
31 char key[10];
32 std::cout << "Enter a non blocking keyboard event detection loop..." << std::endl;
33 do {
34 bool event = vpDisplay::getKeyboardEvent(I, &key[0], false);
35 if (event) {
36 std::cout << "Key detected: " << key << std::endl;
37 cpt_event++;
38 }
39 vpTime::wait(5); // wait 5 ms
40 } while (cpt_event < 5);
41
42#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
43 delete d;
44#endif
45
46#else
47 std::cout << "No gui available to display an image..." << std::endl;
48#endif
49
50 return EXIT_SUCCESS;
51}
Class that defines generic functionalities for display.
Definition vpDisplay.h:171
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)
Definition of the vpImage class member functions.
Definition vpImage.h:131
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
VISP_EXPORT int wait(double t0, double t)