Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes

CxUtils::Keyboard Class Reference

Static methods for determining if a key is currently being pressed and to generate keyboard/key events. More...

#include <keyboard.h>

List of all members.

Classes

class  Callback
 Callback class to use to get keyboard events. More...

Public Types

enum  Key {
  Any = -1, Invalid = 0, Backspace, Tab,
  Clear, Return, ShiftLock, Pause,
  CapsLock, Escape, Space, PageUp,
  PageDown, End, Home, LeftArrow,
  UpArrow, RightArrow, DownArrow, Select,
  Print, Execute, PrintScreen, Insert,
  Delete, Help, Zero = 0x30, One,
  Two, Three, Four, Five,
  Six, Seven, Eight, Nine,
  A = 0x41, B, C, D,
  E, F, G, H,
  I, J, K, L,
  M, N, O, P,
  Q, R, S, T,
  U, V, W, X,
  Y, Z, Numpad0, Numpad1,
  Numpad2, Numpad3, Numpad4, Numpad5,
  Numpad6, Numpad7, Numpad8, Numpad9,
  Multiply, Add, Separator, Subtract,
  Decimal, Divide, F1, F2,
  F3, F4, F5, F6,
  F7, F8, F9, F10,
  F11, F12, NumLock, ScrollLock,
  LeftShift, RightShift, LeftControl, RightControl,
  Comma, Period, LeftAlt, RightAlt
}
 

Enumeration of different keys available.

More...
typedef std::vector< KeyKeyList

Public Member Functions

 Keyboard ()
 Constructor.
 ~Keyboard ()
 Destructor.
bool RegisterCallback (Callback *cb)
 Register a callback to receive keyboard events.
void RemoveCallback (Callback *cb)
 Remove a callback to receive keyboard events.
bool IsActive () const

Static Public Member Functions

static bool IsKeyDown (const Key key=Any)
 Checks if a key on the keyboard in being pressed.
static Key GetCurrentKey ()
 Gets the current key being pressed.
static KeyList GetPressedKeys ()
static bool FakeKeyPress (const Key key, const bool releaseFlag=true, const bool directX=false)
 Method used to generate a fake keyboard event.
static bool FakeKeyRelease (const Key key, const bool directX=false)
 Method used to generate a fake keyboard event.
static unsigned int LookupHostSystemKey (const Key key)
 Method used to convert from generic key enumeration to OS specific value.
static Key LookupFromHostSystemKey (const unsigned int hostKey)
 Method used to convert from the host system key value to a CxUtils Keyboard::Key enumeration value.
static std::string ToString (const Key key)
 Method used to lookup a string version of a key.
static Key FromString (const std::string &strKey)
 Method used to convert a string to a key value.

Static Public Attributes

static const unsigned int MaxKeys = 256
 Current max supported keys.

Detailed Description

Static methods for determining if a key is currently being pressed and to generate keyboard/key events.

Dependencies for Linux: libx11, libxtst

Definition at line 60 of file keyboard.h.


Member Typedef Documentation

typedef std::vector<Key> CxUtils::Keyboard::KeyList

Definition at line 173 of file keyboard.h.


Member Enumeration Documentation

Enumeration of different keys available.

Enumerator:
Any 
Invalid 
Backspace 
Tab 
Clear 
Return 
ShiftLock 
Pause 
CapsLock 
Escape 
Space 
PageUp 
PageDown 
End 
Home 
LeftArrow 
UpArrow 
RightArrow 
DownArrow 
Select 
Print 
Execute 
PrintScreen 
Insert 
Delete 
Help 
Zero 
One 
Two 
Three 
Four 
Five 
Six 
Seven 
Eight 
Nine 
A 
B 
C 
D 
E 
F 
G 
H 
I 
J 
K 
L 
M 
N 
O 
P 
Q 
R 
S 
T 
U 
V 
W 
X 
Y 
Z 
Numpad0 
Numpad1 
Numpad2 
Numpad3 
Numpad4 
Numpad5 
Numpad6 
Numpad7 
Numpad8 
Numpad9 
Multiply 
Add 
Separator 
Subtract 
Decimal 
Divide 
F1 
F2 
F3 
F4 
F5 
F6 
F7 
F8 
F9 
F10 
F11 
F12 
NumLock 
ScrollLock 
LeftShift 
RightShift 
LeftControl 
RightControl 
Comma 
Period 
LeftAlt 
RightAlt 

Definition at line 70 of file keyboard.h.


Constructor & Destructor Documentation

Keyboard::Keyboard (  )

Constructor.

Definition at line 128 of file keyboard.cpp.

Keyboard::~Keyboard (  )

Destructor.

Definition at line 139 of file keyboard.cpp.


Member Function Documentation

bool Keyboard::FakeKeyPress ( const Key  key,
const bool  releaseFlag = true,
const bool  directX = false 
) [static]

Method used to generate a fake keyboard event.

Parameters:
[in]keyThe key to generate a fake keyboard event for.
[in]releaseFlagIf true, the method will also generate a key up command after the key down event.
[in]directXFlag only used in Windows. If you are tryign to fake a key press for a DirectX application (video games) then you must set this to true because direct X uses hardware scan codes, which other applications do not.
Returns:
True on success, otherwise false.

Definition at line 443 of file keyboard.cpp.

bool Keyboard::FakeKeyRelease ( const Key  key,
const bool  directX = false 
) [static]

Method used to generate a fake keyboard event.

Parameters:
[in]keyThe key to generate a fake keyboard event for.
[in]directXFlag only used in Windows. If you are tryign to fake a key press for a DirectX application (video games) then you must set this to true because direct X uses hardware scan codes, which other applications do not.
Returns:
True on success, otherwise false.

Definition at line 513 of file keyboard.cpp.

Keyboard::Key Keyboard::FromString ( const std::string &  strKey ) [static]

Method used to convert a string to a key value.

Parameters:
[in]strKeyString verion of key to convert to enumeration.
Returns:
"Invalid" on failure, otherwise a enumeration of the key.

Definition at line 2016 of file keyboard.cpp.

Keyboard::Key Keyboard::GetCurrentKey (  ) [static]

Gets the current key being pressed.

Returns:
The value of the current key that is down.

Definition at line 360 of file keyboard.cpp.

Keyboard::KeyList Keyboard::GetPressedKeys (  ) [static]
Returns:
List of all the keys currently being pressed.

Definition at line 414 of file keyboard.cpp.

bool CxUtils::Keyboard::IsActive (  ) const [inline]

Definition at line 205 of file keyboard.h.

bool Keyboard::IsKeyDown ( const Key  key = Any ) [static]

Checks if a key on the keyboard in being pressed.

Parameters:
[in]keyThe key to check for being pressed. If the value is Any, default, then the method will check for any key that is pressed. The console or program does not have to be active (this is a passive method).
Returns:
True if the key is currently down.

Definition at line 266 of file keyboard.cpp.

Keyboard::Key Keyboard::LookupFromHostSystemKey ( const unsigned int  hostKey ) [static]

Method used to convert from the host system key value to a CxUtils Keyboard::Key enumeration value.

Parameters:
[in]hostKeythe host system key to convert from.
Returns:
None on failure, otherwise correct key mapping.

Definition at line 1187 of file keyboard.cpp.

unsigned int Keyboard::LookupHostSystemKey ( const Key  key ) [static]

Method used to convert from generic key enumeration to OS specific value.

Parameters:
[in]keyThe key to perform lookup for.
Returns:
0 on failure, otherwise the host system key value match.

Definition at line 567 of file keyboard.cpp.

bool Keyboard::RegisterCallback ( Callback cb )

Register a callback to receive keyboard events.

Parameters:
[in]cbPointer to callback object to run when keys are pressed or released.
Returns:
True on success, false on failure.

Definition at line 156 of file keyboard.cpp.

void Keyboard::RemoveCallback ( Callback cb )

Remove a callback to receive keyboard events.

Parameters:
[in]cbPointer to callback object to remove.

Definition at line 181 of file keyboard.cpp.

std::string Keyboard::ToString ( const Key  key ) [static]

Method used to lookup a string version of a key.

Parameters:
[in]keyThe key to get string equivalent for.
Returns:
"Invalid" on failure, otherwise a string representation of the key.

Definition at line 1699 of file keyboard.cpp.


Member Data Documentation

const unsigned int CxUtils::Keyboard::MaxKeys = 256 [static]

Current max supported keys.

Definition at line 63 of file keyboard.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines