OMK::Inp::KeyListener Class Reference
[User inputs]

Input listener for a key. More...

#include <OMKKeyListener.h>

Inheritance diagram for OMK::Inp::KeyListener:

Inheritance graph
[legend]
Collaboration diagram for OMK::Inp::KeyListener:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual ~KeyListener ()
 The destructor.

Static Public Member Functions

static const EventIdentifier getKeyPressCode (const std::string &code)
 To get the event identifier for key press.
static const EventIdentifier getKeyReleaseCode (const std::string &code)
 To get the event identifier for key release.

Private Member Functions

 KeyListener (ExtensibleSimulatedObject *sender, const std::string &code, const ConfigurationParameterDescriptor *node)
 The constructor.
virtual bool keyPressed (const OIS::KeyEvent &e)
 Dispatches key pressed event.
virtual bool keyReleased (const OIS::KeyEvent &e)
 Dispatches key released event.
bool sendKeyEvent (OIS::KeyCode key, bool pressed)
 Inner method to send the event.
void addListeningObject (const Name &object)
 Add a object in the list.

Private Attributes

std::vector< Name_listeningObjects
 The ojbects' name which will be informed of the key press and release.
OIS::KeyCode _code
 The code of the listening key.
const EventIdentifier _keyPressedCode
 The event identifier for key press.
const EventIdentifier _keyReleasedCode
 The event identifier for key release.

Friends

class InputExtension
 This is the only one which can create this object.

Detailed Description

Input listener for a key.

Date:
2007-03-12
Author:
Benoît Chanclou
Module description :
This listener sends an event to the object listed in its list when the key is pressed or released.

To add this listener you don't have to declare it as an input listener, see Keys parameter in InputExtension for more details.

Definition at line 44 of file OMKKeyListener.h.


Constructor & Destructor Documentation

KeyListener::KeyListener ( ExtensibleSimulatedObject sender,
const std::string &  code,
const ConfigurationParameterDescriptor node 
) [private]

The constructor.

It is a private one because only the friend class InputExtension, can create it.

Definition at line 21 of file OMKKeyListener.cpp.

References _listeningObjects, and OMK::ParametersAccessor::get().

00024 : InputListener( sender, code, node ),
00025 _code( retrieveCode( code ) ),
00026 _keyPressedCode( getKeyPressCode( code ) ), 
00027 _keyReleasedCode( getKeyReleaseCode( code ) )
00028 {
00029   ParametersAccessor::get( node, code, _listeningObjects ) ;
00030 }

KeyListener::~KeyListener (  )  [virtual]

The destructor.

Definition at line 32 of file OMKKeyListener.cpp.

00033 {
00034 }


Member Function Documentation

const EventIdentifier KeyListener::getKeyPressCode ( const std::string &  code  )  [static]

To get the event identifier for key press.

Parameters:
[in] code The code of the key, see the valid codes.
Returns:
Returns the event identifier for the event sent for the key corresponding to the code is pressed.

Definition at line 11 of file OMKKeyListener.cpp.

Referenced by OMK::Inp::GenericKeyExtension< OMK::ExtensibleSimulatedObject >::loadExtensionParameters().

00012 {
00013   return EventIdentifier( "Key_" + code + "_is_pressed" ) ;
00014 }

const EventIdentifier KeyListener::getKeyReleaseCode ( const std::string &  code  )  [static]

To get the event identifier for key release.

Parameters:
[in] code The code of the key, see the valid codes.
Returns:
Returns the event identifier for the event sent for the key corresponding to the code is released.

Definition at line 16 of file OMKKeyListener.cpp.

Referenced by OMK::Inp::InputExtension::initCallBackForKey(), and OMK::Inp::GenericKeyExtension< OMK::ExtensibleSimulatedObject >::loadExtensionParameters().

00017 {
00018   return EventIdentifier( "Key_" + code + "_is_released" ) ;
00019 }

virtual bool OMK::Inp::KeyListener::keyPressed ( const OIS::KeyEvent &  e  )  [inline, private, virtual]

Dispatches key pressed event.

Definition at line 68 of file OMKKeyListener.h.

00068 { return sendKeyEvent( e.key, true ) ; }

virtual bool OMK::Inp::KeyListener::keyReleased ( const OIS::KeyEvent &  e  )  [inline, private, virtual]

Dispatches key released event.

Definition at line 70 of file OMKKeyListener.h.

00070 { return sendKeyEvent( e.key, false ) ; }

bool KeyListener::sendKeyEvent ( OIS::KeyCode  key,
bool  pressed 
) [private]

Inner method to send the event.

Call by keyPressed and keyReleased.

Definition at line 36 of file OMKKeyListener.cpp.

References _code, _keyPressedCode, _keyReleasedCode, _listeningObjects, and OMK::Inp::InputListener::sendEvent().

00037 {
00038   if( _code == key )
00039   {
00040     for( std::vector< Name >::iterator i = _listeningObjects.begin() ;
00041          i != _listeningObjects.end() ;
00042          i++ )
00043     {
00044       sendEvent( *i, pressed ? _keyPressedCode : _keyReleasedCode ) ;
00045     }
00046   }
00047   return true ;
00048 }

void KeyListener::addListeningObject ( const Name object  )  [private]

Add a object in the list.

Definition at line 50 of file OMKKeyListener.cpp.

References _listeningObjects.

Referenced by OMK::Inp::InputExtension::addKeyListener().

00051 {
00052   _listeningObjects.insert( _listeningObjects.end(), object ) ;
00053 }


Friends And Related Function Documentation

friend class InputExtension [friend]

This is the only one which can create this object.

Definition at line 49 of file OMKKeyListener.h.


Member Data Documentation

std::vector< Name > OMK::Inp::KeyListener::_listeningObjects [private]

The ojbects' name which will be informed of the key press and release.

Definition at line 77 of file OMKKeyListener.h.

Referenced by addListeningObject(), KeyListener(), and sendKeyEvent().

OIS::KeyCode OMK::Inp::KeyListener::_code [private]

The code of the listening key.

Definition at line 79 of file OMKKeyListener.h.

Referenced by sendKeyEvent().

const EventIdentifier OMK::Inp::KeyListener::_keyPressedCode [private]

The event identifier for key press.

Definition at line 81 of file OMKKeyListener.h.

Referenced by sendKeyEvent().

const EventIdentifier OMK::Inp::KeyListener::_keyReleasedCode [private]

The event identifier for key release.

Definition at line 83 of file OMKKeyListener.h.

Referenced by sendKeyEvent().


logo OpenMask

Documentation generated on Mon Jun 9 11:46:04 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007