Visual Servoing Platform  version 3.6.1 under development (2024-06-19)
vpKeyboard Class Reference

#include <visp3/io/vpKeyboard.h>

Public Member Functions

 vpKeyboard ()
 
virtual ~vpKeyboard ()
 
int kbhit ()
 
int getchar ()
 

Detailed Description

Keyboard management under unix (Linux or OSX). This class is not available under windows.

Gets a key from the keyboard without waiting for the "Enter" key.

Warning
The key that was pressed is only detected if the terminal where the binary was launched is active.
vpKeyboard keyboard; // Turn on keyboard raw mode
int c;
while (...) {
...
if (keyboard.kbhit()) { // Detect if a key was pressed
c = keyboard.getchar (void); // Get the pressed key
if (c == 'q' || c == 'Q') {
break; // Quit the while()
}
...
}
}
// Keyboard raw mode is turned off by the vpKeyboard destructor
Keyboard management under unix (Linux or OSX). This class is not available under windows.
Definition: vpKeyboard.h:83
int getchar()
Definition: vpKeyboard.cpp:77
int kbhit()
Definition: vpKeyboard.cpp:93
Examples
ClassUsingPclViewer.cpp, keyboard.cpp, keyboardControlBebop2.cpp, and testPixhawkDroneKeyboard.cpp.

Definition at line 82 of file vpKeyboard.h.

Constructor & Destructor Documentation

◆ vpKeyboard()

BEGIN_VISP_NAMESPACE vpKeyboard::vpKeyboard ( )

Activates the raw mode to read keys in an non blocking way.

Definition at line 54 of file vpKeyboard.cpp.

References vpImage< Type >::init().

◆ ~vpKeyboard()

vpKeyboard::~vpKeyboard ( )
virtual

Stops the raw mode.

Definition at line 67 of file vpKeyboard.cpp.

Member Function Documentation

◆ getchar()

int vpKeyboard::getchar ( )

Get the hit key. kbhit() indicates if a key was hitten.

Examples
keyboard.cpp, keyboardControlBebop2.cpp, and testPixhawkDroneKeyboard.cpp.

Definition at line 77 of file vpKeyboard.cpp.

References vpException::fatalError.

◆ kbhit()

int vpKeyboard::kbhit ( )
Returns
1 : if a key was hit.
Examples
ClassUsingPclViewer.cpp, keyboard.cpp, keyboardControlBebop2.cpp, and testPixhawkDroneKeyboard.cpp.

Definition at line 93 of file vpKeyboard.cpp.

References vpException::fatalError.