Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F624279
keyboard.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None
keyboard.h
View Options
#ifndef _paintown_keyboard_h
#define _paintown_keyboard_h
#include
<map>
#include
<vector>
#include
<stdint.h>
/* handles allegro key[] array better than keypressed()
* and readkey()
*/
class
Keyboard
{
private
:
Keyboard
();
public
:
friend
class
InputManager
;
typedef
const
int
KeyType
;
typedef
uint32_t
unicode_t
;
struct
KeyData
{
KeyData
()
:
key
(
-1
),
unicode
(
-1
),
enabled
(
false
){
}
KeyData
(
int
key
,
unicode_t
unicode
,
bool
enabled
)
:
key
(
key
),
unicode
(
unicode
),
enabled
(
enabled
){
}
int
key
;
/* Converted to a unicode character in UTF-32 */
unicode_t
unicode
;
/* whether the key is being pressed */
bool
enabled
;
};
/*
typedef void (*ObserverCallback)(const KeyData & data, void * extra);
struct Observer{
Observer():
callback(NULL),
extra(NULL){
}
Observer(ObserverCallback callback, void * extra):
callback(callback),
extra(extra){
}
ObserverCallback callback;
void * extra;
};
*/
/* poll:
* Put the keys in Allegro's key[] array into our map of int -> bool
*/
void
poll
();
/* wait for all keys to be released */
void
wait
();
/* []:
* Extract a boolean value given a key number
*/
#if 0
inline bool operator[] ( const int i ){
/* if the key has been pressed for the first time return true */
if ( my_keys[ i ] < 0 ){
my_keys[ i ] = 1;
return true;
}
bool b = my_keys[ i ] > key_delay[ i ];
if ( b ){
my_keys[ i ] = 1;
}
return b;
}
#endif
/* keypressed:
* Returns true if a key is pressed
*/
bool
keypressed
();
/* readKeys:
* Store all pressed keys in a user supplied vector
*/
void
readKeys
(
std
::
vector
<
int
>
&
all_keys
);
void
readBufferedKeys
(
std
::
vector
<
int
>
&
keys
);
std
::
vector
<
KeyData
>
readData
();
std
::
vector
<
unicode_t
>
readText
();
// int readKey();
void
clear
();
/* sets the latest repeat state. popping the state restores the previous state */
static
void
pushRepeatState
(
bool
enabled
);
static
void
popRepeatState
();
/* true on systems that probably have a keyboard, like pc.
* false on ps3, wii, etc.
*/
static
bool
haveKeyboard
();
void
setDelay
(
const
int
key
,
const
int
delay
);
void
setAllDelay
(
const
int
delay
);
inline
const
std
::
vector
<
KeyData
>
&
getBufferedKeys
()
const
{
return
buffer
;
}
static
const
char
*
keyToName
(
int
key
);
static
bool
isNumber
(
int
key
);
static
bool
isChar
(
int
key
);
static
bool
isAlpha
(
int
key
);
static
KeyType
Key_A
;
static
KeyType
Key_B
;
static
KeyType
Key_C
;
static
KeyType
Key_D
;
static
KeyType
Key_E
;
static
KeyType
Key_F
;
static
KeyType
Key_G
;
static
KeyType
Key_H
;
static
KeyType
Key_I
;
static
KeyType
Key_J
;
static
KeyType
Key_K
;
static
KeyType
Key_L
;
static
KeyType
Key_M
;
static
KeyType
Key_N
;
static
KeyType
Key_O
;
static
KeyType
Key_P
;
static
KeyType
Key_Q
;
static
KeyType
Key_R
;
static
KeyType
Key_S
;
static
KeyType
Key_T
;
static
KeyType
Key_U
;
static
KeyType
Key_V
;
static
KeyType
Key_W
;
static
KeyType
Key_X
;
static
KeyType
Key_Y
;
static
KeyType
Key_Z
;
static
KeyType
Key_0
;
static
KeyType
Key_1
;
static
KeyType
Key_2
;
static
KeyType
Key_3
;
static
KeyType
Key_4
;
static
KeyType
Key_5
;
static
KeyType
Key_6
;
static
KeyType
Key_7
;
static
KeyType
Key_8
;
static
KeyType
Key_9
;
static
KeyType
Key_0_PAD
;
static
KeyType
Key_1_PAD
;
static
KeyType
Key_2_PAD
;
static
KeyType
Key_3_PAD
;
static
KeyType
Key_4_PAD
;
static
KeyType
Key_5_PAD
;
static
KeyType
Key_6_PAD
;
static
KeyType
Key_7_PAD
;
static
KeyType
Key_8_PAD
;
static
KeyType
Key_9_PAD
;
static
KeyType
Key_F1
;
static
KeyType
Key_F2
;
static
KeyType
Key_F3
;
static
KeyType
Key_F4
;
static
KeyType
Key_F5
;
static
KeyType
Key_F6
;
static
KeyType
Key_F7
;
static
KeyType
Key_F8
;
static
KeyType
Key_F9
;
static
KeyType
Key_F10
;
static
KeyType
Key_F11
;
static
KeyType
Key_F12
;
static
KeyType
Key_ESC
;
static
KeyType
Key_TILDE
;
static
KeyType
Key_MINUS
;
static
KeyType
Key_EQUALS
;
static
KeyType
Key_BACKSPACE
;
static
KeyType
Key_TAB
;
static
KeyType
Key_OPENBRACE
;
static
KeyType
Key_CLOSEBRACE
;
static
KeyType
Key_ENTER
;
static
KeyType
Key_COLON
;
static
KeyType
Key_QUOTE
;
static
KeyType
Key_BACKSLASH
;
static
KeyType
Key_BACKSLASH2
;
static
KeyType
Key_COMMA
;
static
KeyType
Key_STOP
;
static
KeyType
Key_SLASH
;
static
KeyType
Key_SPACE
;
static
KeyType
Key_INSERT
;
static
KeyType
Key_DEL
;
static
KeyType
Key_HOME
;
static
KeyType
Key_END
;
static
KeyType
Key_PGUP
;
static
KeyType
Key_PGDN
;
static
KeyType
Key_LEFT
;
static
KeyType
Key_RIGHT
;
static
KeyType
Key_UP
;
static
KeyType
Key_DOWN
;
static
KeyType
Key_SLASH_PAD
;
static
KeyType
Key_ASTERISK
;
static
KeyType
Key_MINUS_PAD
;
static
KeyType
Key_PLUS_PAD
;
static
KeyType
Key_DEL_PAD
;
static
KeyType
Key_ENTER_PAD
;
static
KeyType
Key_PRTSCR
;
static
KeyType
Key_PAUSE
;
static
KeyType
Key_ABNT_C1
;
static
KeyType
Key_YEN
;
static
KeyType
Key_KANA
;
static
KeyType
Key_CONVERT
;
static
KeyType
Key_NOCONVERT
;
static
KeyType
Key_AT
;
static
KeyType
Key_CIRCUMFLEX
;
static
KeyType
Key_COLON2
;
static
KeyType
Key_KANJI
;
static
KeyType
Key_EQUALS_PAD
;
static
KeyType
Key_BACKQUOTE
;
static
KeyType
Key_SEMICOLON
;
static
KeyType
Key_COMMAND
;
/*
static KeyType Key_UNKNOWN1;
static KeyType Key_UNKNOWN2;
static KeyType Key_UNKNOWN3;
static KeyType Key_UNKNOWN4;
static KeyType Key_UNKNOWN5;
static KeyType Key_UNKNOWN6;
static KeyType Key_UNKNOWN7;
static KeyType Key_UNKNOWN8;
*/
static
KeyType
Key_MODIFIERS
;
static
KeyType
Key_LSHIFT
;
static
KeyType
Key_RSHIFT
;
static
KeyType
Key_LCONTROL
;
static
KeyType
Key_RCONTROL
;
static
KeyType
Key_ALT
;
static
KeyType
Key_ALTGR
;
static
KeyType
Key_LWIN
;
static
KeyType
Key_RWIN
;
static
KeyType
Key_MENU
;
static
KeyType
Key_SCRLOCK
;
static
KeyType
Key_NUMLOCK
;
static
KeyType
Key_CAPSLOCK
;
void
press
(
KeyType
key
,
unicode_t
unicode
);
void
release
(
KeyType
key
);
/*
virtual void addObserver(ObserverCallback observer, void * extra);
virtual void removeObserver(ObserverCallback observer, void * extra);
*/
protected
:
static
void
disableKeyRepeat
();
static
void
enableKeyRepeat
();
// std::map<int,int> my_keys;
std
::
map
<
int
,
int
>
key_delay
;
// std::vector<Observer> observers;
std
::
map
<
KeyType
,
KeyData
>
keyState
;
std
::
vector
<
KeyData
>
buffer
;
bool
enableBuffer
;
static
std
::
vector
<
bool
>
repeatState
;
};
#endif
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Sat, Nov 14, 10:10 PM (1 d, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
140533
Default Alt Text
keyboard.h (6 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline