Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ArKeyHandler Class Reference

This class will read input from the keyboard. More...

#include <ArKeyHandler.h>

List of all members.

Public Types

enum  KEY {
  UP = 256, DOWN, LEFT, RIGHT,
  ESCAPE, SPACE, TAB, ENTER,
  BACKSPACE, _StartFKeys, F1, F2,
  F3, F4, F5, F6,
  F7, F8, F9, F10,
  F11, F12, _EndFKeys, PAGEUP,
  PAGEDOWN, HOME, END, INSERT,
  DEL
}
 These are enums for the non-ascii keys. More...

Public Member Functions

bool addKeyHandler (int keyToHandle, ArFunctor *functor)
 This adds a keyhandler, when the keyToHandle is hit, functor will fire.
 ArKeyHandler (bool blocking=false, bool addAriaExitCB=true)
void checkKeys (void)
 intnernal, use addKeyHandler, Checks for keys and handles them
int getKey (void)
bool remKeyHandler (ArFunctor *functor)
 This removes a key handler, by key.
bool remKeyHandler (int keyToHandler)
 This removes a key handler, by key.
void restore (void)
void takeKeys (bool blocking=false)
 ~ArKeyHandler ()

Protected Attributes

ArFunctorC< ArKeyHandlermyAriaExitCB
bool myBlocking
std::map< int, ArFunctor * > myMap
termios myOriginalTermios
bool myRestored


Detailed Description

This class will read input from the keyboard.

This class is for handling input from the keyboard, you just addKeyHandler the keys you want to deal with.

You should also register the keyhandler with Aria::setKeyHandler, and before you create a key handler you should see if one is already there with Aria::getKeyHandler.

You can attach a key handler to a robot with ArRobot::attachKeyHandler which will put a task into the robots list of tasks so that it'll get checked every cycle or you can just call checkKeys yourself (like in its own thread or in the main thread). You should only attach a key handler to one robot, even if you're using multiple robots.

Definition at line 58 of file ArKeyHandler.h.


Member Enumeration Documentation

enum ArKeyHandler::KEY
 

These are enums for the non-ascii keys.

Enumeration values:
UP  Up arrow (keypad or 4 key dirs).
DOWN  Down arrow (keypad or 4 key dirs).
LEFT  Left arrow (keypad or 4 key dirs).
RIGHT  Right arrow (keypad or 4 key dirs).
ESCAPE  Escape key.
SPACE  Space key.
TAB  Tab key.
ENTER  Enter key.
BACKSPACE  Backspace key.
_StartFKeys  F key offset (don't use).
F1  F1.
F2  F2.
F3  F3.
F4  F4.
F5  F5 (not supported on Windows yet).
F6  F6 (not supported on Windows yet).
F7  F7 (not supported on Windows yet).
F8  F8 (not supported on Windows yet).
F9  F9 (not supported on Windows yet).
F10  F10 (not supported on Windows yet).
F11  F11 (not supported on Windows yet).
F12  F12 (not supported on Windows yet).
_EndFKeys  F key range (don't use).
PAGEUP  Page Up (not supported on Windows yet).
PAGEDOWN  Page Down (not supported on Windows yet).
HOME  Home key (not supported on Windows yet).
END  End key (not supported on Windows yet).
INSERT  Insert key (not supported on Windows yet).
DEL  Special delete key (often forward-delete) (not supported on Windows yet).

Definition at line 70 of file ArKeyHandler.h.


Constructor & Destructor Documentation

ArKeyHandler::ArKeyHandler bool  blocking = false,
bool  addAriaExitCB = true
 

This object will take over key capture when constructed, and release key capture when destroyed.

Definition at line 47 of file ArKeyHandler.cpp.

References Aria::addExitCallback(), ArFunctor::setName(), and takeKeys().

ArKeyHandler::~ArKeyHandler  ) 
 

Destructor. Reseases control of the keyboard and restores state before this key handler was created.

Definition at line 56 of file ArKeyHandler.cpp.

References restore().


Member Function Documentation

bool ArKeyHandler::addKeyHandler int  keyToHandle,
ArFunctor functor
 

This adds a keyhandler, when the keyToHandle is hit, functor will fire.

Parameters:
keyToHandle this is an ascii character, such as 'a' or '1' or '[', or a member of the KEY enum.
functor a functor to call when the given key is pressed
Returns:
true if the addKeyHandler succeeded, which means that the key added was unique and it will be handled... false means that the add failed, because there was already a keyHandler in place for that key

Definition at line 103 of file ArKeyHandler.cpp.

References ArLog::log().

Referenced by ArMode::ArMode(), ArSickLogger::ArSickLogger(), ArRatioInputKeydrive::takeKeys(), and ArActionKeydrive::takeKeys().

int ArKeyHandler::getKey void   ) 
 

internal, use addKeyHandler instead... Gets a key from the stdin if ones available, -1 if there aren't any available

Definition at line 194 of file ArKeyHandler.cpp.

References BACKSPACE, DEL, DOWN, END, ENTER, ESCAPE, F1, F10, F11, F12, F2, F3, F4, F5, F6, F7, F8, F9, HOME, INSERT, LEFT, PAGEDOWN, PAGEUP, RIGHT, SPACE, TAB, and UP.

Referenced by checkKeys().

bool ArKeyHandler::remKeyHandler ArFunctor functor  ) 
 

This removes a key handler, by key.

Parameters:
keyToHandle the functor to remove
Returns:
true if the remKeyHandler succeeded, which means that the key wad found and rmeoved... false means that the remove failed because there was no key for that

Definition at line 145 of file ArKeyHandler.cpp.

References ArLog::log().

bool ArKeyHandler::remKeyHandler int  keyToHandle  ) 
 

This removes a key handler, by key.

Parameters:
keyToHandle this is an ascii character, such as 'a' or '1' or '[', or a member of the KEY enum.
Returns:
true if the remKeyHandler succeeded, which means that the key wad found and rmeoved... false means that the remove failed because there was no key for that

Definition at line 125 of file ArKeyHandler.cpp.

References ArLog::log().

Referenced by ArRatioInputKeydrive::giveUpKeys(), ArActionKeydrive::giveUpKeys(), and ArMode::~ArMode().

void ArKeyHandler::restore void   ) 
 

Sets stdin back to its original settings, if its been restored it won't read anymore. For internal or special use, since it's called in the destructor.

Definition at line 83 of file ArKeyHandler.cpp.

Referenced by ArRobot::stopRunning(), and ~ArKeyHandler().

void ArKeyHandler::takeKeys bool  blocking = false  ) 
 

Takes the key control over. For internal or special use, since it's called in the constructor.

Definition at line 61 of file ArKeyHandler.cpp.

Referenced by ArKeyHandler().


The documentation for this class was generated from the following files:
Generated on Wed Oct 19 12:56:49 2005 for Aria by  doxygen 1.4.0