Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
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
6
using namespace
VISP_NAMESPACE_NAME
;
7
#endif
8
9
int
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
22
vpDisplay::display
(I);
23
// Flush the foreground and background display
24
vpDisplay::flush
(I);
25
// Wait for keyboard event
26
std::cout <<
"Waiting a keyboard event..."
<< std::endl;
27
vpDisplay::getKeyboardEvent
(I,
true
);
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
}
vpDisplay
Class that defines generic functionalities for display.
Definition
vpDisplay.h:171
vpDisplay::getKeyboardEvent
static bool getKeyboardEvent(const vpImage< unsigned char > &I, bool blocking=true)
Definition
vpDisplay_uchar.cpp:1102
vpDisplay::display
static void display(const vpImage< unsigned char > &I)
Definition
vpDisplay_uchar.cpp:869
vpDisplay::flush
static void flush(const vpImage< unsigned char > &I)
Definition
vpDisplay_uchar.cpp:845
vpDisplay::SCALE_AUTO
@ SCALE_AUTO
Definition
vpDisplay.h:177
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:131
VISP_NAMESPACE_NAME
Definition
vpEigenConversion.h:44
vpDisplayFactory::createDisplay
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
Definition
vpDisplayFactory.h:142
vpDisplayFactory::allocateDisplay
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.
Definition
vpDisplayFactory.h:68
vpTime::wait
VISP_EXPORT int wait(double t0, double t)
yolo-centering-task-afma6.d
d
Definition
yolo-centering-task-afma6.py:273
tutorial
image
tutorial-event-keyboard.cpp
Generated by
1.17.0