blob: 2c25609cc7ac8d77180746cc8a5fd227d48c245a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*
client/key.h
This file is part of the Osirion project and is distributed under
the terms and conditions of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CLIENT_KEY_H__
#define __INCLUDED_CLIENT_KEY_H__
#include "SDL2/SDL.h"
#include <string>
#include "client/action.h"
namespace client
{
/**
* @brief a key on the keyboard
* a Key instance can contain any kind of 'key' like a keyboard key,
* a mouse button, or a joystick button. Any key can be bound to
* a command string or an action.
* @see Action
* @see Keyboard
*/
class Key
{
public:
/// define a new key
Key(const unsigned int scancode, const char *name, const char ascii = 0);
~Key();
/// key modifiers
enum Modifier { None = 0, Shift = KMOD_LSHIFT + KMOD_RSHIFT, Ctrl = KMOD_LCTRL + KMOD_RCTRL, Alt = KMOD_LALT + KMOD_RALT };
/// clear all binds
void clear();
/// set the bind for a specific modifier
void assign(Modifier mod, const char *bind, Action *action = 0);
/// clear the bind for a specific modifier
void clear(Modifier mod);
/// return the bind for a specific modifier
std::string const & bind(Modifier mod) const;
/// return the action this key is bound to, 0 if unbound
inline Action *action() const {
return key_action;
}
/// first time the key was pressed since previous release
inline float pressed() const {
return key_pressed;
}
/// last time the key was pressed (includes repeats)
inline float lastpressed() const {
return key_lastpressed;
}
/// time the key was pressed when it is released
inline float waspressed() const {
return key_waspressed;
}
inline std::string const & name() const {
return key_name;
}
inline char ascii() const {
return key_ascii;
}
inline unsigned int scancode() const {
return key_scancode;
}
float key_pressed;
float key_lastpressed;
float key_waspressed;
private:
std::string key_name;
unsigned int key_scancode;
char key_ascii;
Action *key_action;
std::string key_bind;
std::string key_bind_shift;
std::string key_bind_ctrl;
std::string key_bind_alt;
};
} // namespace client
#endif // __INCLUDED_CLIENT_KEY_H__
|