Castle Battle  1.0
Public Member Functions | Private Attributes | List of all members
KEYBOARD::Keyboard Class Reference

Keyboard class will handle keyboard input events. More...

#include <keyboard.h>

Inheritance diagram for KEYBOARD::Keyboard:

Public Member Functions

 Keyboard ()
 Default constructor set initial state of the keys (not pressed) and map the keyboard with the actions. More...
 
void mapKeyboard (const std::vector< Key > keys=KEYBOARD_DEFAULT)
 Map keyboard with the keys. More...
 
virtual bool OnEvent (const SEvent &event)
 Virtual method called by irrlicht whenever a key is pressed. More...
 
KeygetLastKey ()
 Get last key pressed. More...
 
KeyIsKeyDown ()
 Return a pressed ::Key. More...
 
void resetLastKey ()
 Reset last key pressed variable. More...
 

Private Attributes

bool keyDown [KEY_KEY_CODES_COUNT]
 Array of keys. More...
 
std::vector< KeymapKeys
 Map key with the ACTION_KEYBOARD specified in the Keyboard vector. More...
 
Keylastkey
 Last key pressed. More...
 

Detailed Description

Keyboard class will handle keyboard input events.

Constructor & Destructor Documentation

◆ Keyboard()

Keyboard::Keyboard ( )

Default constructor set initial state of the keys (not pressed) and map the keyboard with the actions.

9  {
10  for(u32 i = 0; i < KEY_KEY_CODES_COUNT; i++){
11  this->keyDown[i] = false;
12  }
13  this->lastkey = new Key(ACTION_NULL,irr::KEY_EREOF);
14 
15  this->mapKeyboard();
16 }
void mapKeyboard(const std::vector< Key > keys=KEYBOARD_DEFAULT)
Map keyboard with the keys.
Definition: keyboard.cpp:41
bool keyDown[KEY_KEY_CODES_COUNT]
Array of keys.
Definition: keyboard.h:52
Key * lastkey
Last key pressed.
Definition: keyboard.h:56
Definition: keyboard.h:20
Key is a class that describe a irrlicht EKEY_CODE and what ACTION_KEYBOARD is referring.
Definition: keyboard.h:23

Member Function Documentation

◆ getLastKey()

Key * Keyboard::getLastKey ( )

Get last key pressed.

50  {
51  return this->lastkey;
52 }
Key * lastkey
Last key pressed.
Definition: keyboard.h:56

◆ IsKeyDown()

Key * Keyboard::IsKeyDown ( )

Return a pressed ::Key.

This method will check only keys ::mapKeys

See also
::mapKeyboard
KEYBOARD_DEFAULT
::Key
24  {
25  for(std::vector<Key>::const_iterator it = this->mapKeys.begin(); it != this->mapKeys.end(); ++it){
26 // std::cout<<it->k<<std::endl;
27 
28  if(this->keyDown[it->key]) {
29  Key* lastkey = new Key(it->action,it->key);
30  if(this->lastkey->action == ACTION_NULL || this->lastkey->action != lastkey->action) this->lastkey = lastkey;
31  return lastkey;
32  }
33  }
34  return 0; // null
35 
36 
37 // if(this->keyDown[keyCode]) return keyCode;
38 // else (EKEY_CODE)0x0;
39 
40 };
ACTION_KEYBOARD action
Definition: keyboard.h:26
std::vector< Key > mapKeys
Map key with the ACTION_KEYBOARD specified in the Keyboard vector.
Definition: keyboard.h:54
bool keyDown[KEY_KEY_CODES_COUNT]
Array of keys.
Definition: keyboard.h:52
Key * lastkey
Last key pressed.
Definition: keyboard.h:56
Definition: keyboard.h:20
Key is a class that describe a irrlicht EKEY_CODE and what ACTION_KEYBOARD is referring.
Definition: keyboard.h:23

◆ mapKeyboard()

void Keyboard::mapKeyboard ( const std::vector< Key keys = KEYBOARD_DEFAULT)

Map keyboard with the keys.

In particular given a configuration array of KEYBOARD::Key the KEYBOARD::Keyboard::IsKeyDown() method will check these key and will return the corresponding ACTION_KEYBOARD Default configuration see KEYBOARD_DEFAULT

Parameters
keysstd::vector<Key>. Optional
See also
::Key
41  {
42 
43 // if(keys == 0) this->mapKeys.push_back(Key(INCLINATE_UP, KEY_KEY_W));
44 // std::cout<<" "<<keys[0].action<<" "<<keys[1].action<<" "<<keys[2].action<<" "<<keys[3].action<<std::endl;
45  this->mapKeys.clear();
46  this->mapKeys = keys;
47 // std::cout<<this->mapKeys.size()<<std::endl;
48 };
std::vector< Key > mapKeys
Map key with the ACTION_KEYBOARD specified in the Keyboard vector.
Definition: keyboard.h:54

◆ OnEvent()

bool Keyboard::OnEvent ( const SEvent &  event)
virtual

Virtual method called by irrlicht whenever a key is pressed.

17  {
18  if(event.EventType == EET_KEY_INPUT_EVENT)
19  this->keyDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
20  this->IsKeyDown();
21 
22  return false;
23 }
bool keyDown[KEY_KEY_CODES_COUNT]
Array of keys.
Definition: keyboard.h:52
Key * IsKeyDown()
Return a pressed ::Key.
Definition: keyboard.cpp:24

◆ resetLastKey()

void Keyboard::resetLastKey ( )

Reset last key pressed variable.

53  {
54  this->lastkey = new Key(ACTION_NULL,irr::KEY_EREOF);
55 }
Key * lastkey
Last key pressed.
Definition: keyboard.h:56
Definition: keyboard.h:20
Key is a class that describe a irrlicht EKEY_CODE and what ACTION_KEYBOARD is referring.
Definition: keyboard.h:23

Member Data Documentation

◆ keyDown

bool KEYBOARD::Keyboard::keyDown[KEY_KEY_CODES_COUNT]
private

Array of keys.

◆ lastkey

Key* KEYBOARD::Keyboard::lastkey
private

Last key pressed.

◆ mapKeys

std::vector<Key> KEYBOARD::Keyboard::mapKeys
private

Map key with the ACTION_KEYBOARD specified in the Keyboard vector.


The documentation for this class was generated from the following files: