-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathKeyboard.hpp
More file actions
141 lines (122 loc) · 4.2 KB
/
Copy pathKeyboard.hpp
File metadata and controls
141 lines (122 loc) · 4.2 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#ifndef CPP3DS_KEYBOARD_HPP
#define CPP3DS_KEYBOARD_HPP
#ifndef EMULATION
#include <3ds.h>
#endif
namespace cpp3ds {
////////////////////////////////////////////////////////////
/// \brief Give access to the real-time state of the keyboard
///
////////////////////////////////////////////////////////////
class Keyboard {
public :
////////////////////////////////////////////////////////////
/// \brief Key codes
///
////////////////////////////////////////////////////////////
enum Key {
A = 1, ///< The A button
B = 1 << 1, ///< The B button
Select = 1 << 2, ///< The Select button
Start = 1 << 3, ///< The Start button
DPadRight = 1 << 4,
DPadLeft = 1 << 5,
DPadUp = 1 << 6,
DPadDown = 1 << 7,
R = 1 << 8, ///< The R button
L = 1 << 9, ///< The L button
X = 1 << 10, ///< The X button
Y = 1 << 11, ///< The Y button
ZL = 1 << 14, ///< The ZL button (New 3DS only)
ZR = 1 << 15, ///< The ZR button (New 3DS only)
Touchpad = 1 << 20,
CStickRight = 1 << 24,
CStickLeft = 1 << 25,
CStickUp = 1 << 26,
CStickDown = 1 << 27,
CPadRight = 1 << 28,
CPadLeft = 1 << 29,
CPadUp = 1 << 30,
CPadDown = 1 << 31,
Up = DPadUp | CPadUp, ///< Either DPadUp or CPadUp
Down = DPadDown | CPadDown, ///< Either DPadDown or CPadDown
Left = DPadLeft | CPadLeft, ///< Either DPadLeft or CPadLeft
Right = DPadRight | CPadRight, ///< Either DPadRight or CPadRight
};
////////////////////////////////////////////////////////////
/// \brief Check if a key is still being pressed
///
/// \param key Key to check
///
/// \return True if the key is pressed, false otherwise
///
////////////////////////////////////////////////////////////
static bool isKeyDown(Key key);
////////////////////////////////////////////////////////////
/// \brief Check if a key is now being pressed
///
/// \param key Key to check
///
/// \return True if the key is pressed, false otherwise
///
////////////////////////////////////////////////////////////
static bool isKeyPressed(Key key);
////////////////////////////////////////////////////////////
/// \brief Check if a key is now being released
///
/// \param key Key to check
///
/// \return True if the key is pressed, false otherwise
///
////////////////////////////////////////////////////////////
static bool isKeyReleased(Key key);
static float getSlider3D();
static float getSliderVolume();
////////////////////////////////////////////////////////////
/// \brief Update cache values for input
////////////////////////////////////////////////////////////
static void update();
private:
static float m_slider3d;
static float m_sliderVolume;
#ifndef EMULATION
static u32 m_keysHeld;
static u32 m_keysPressed;
static u32 m_keysReleased;
#endif
};
}
#endif
////////////////////////////////////////////////////////////
/// \class cpp3ds::Keyboard
/// \ingroup window
///
/// cpp3ds::Keyboard provides an interface to the state of the
/// keyboard. It only contains static functions (a single
/// keyboard is assumed), so it's not meant to be instantiated.
///
/// This class allows users to query the keyboard state at any
/// time and directly, without having to deal with a window and
/// its events. Compared to the KeyPressed and KeyReleased events,
/// cpp3ds::Keyboard can retrieve the state of a key at any time
/// (you don't need to store and update a boolean on your side
/// in order to know if a key is pressed or released), and you
/// always get the real state of the keyboard, even if keys are
/// pressed or released when your window is out of focus and no
/// event is triggered.
///
/// Usage example:
/// \code
/// if (cpp3ds::Keyboard::isKeyPressed(cpp3ds::Keyboard::Left))
/// {
/// // move left...
/// }
/// else if (cpp3ds::Keyboard::isKeyPressed(cpp3ds::Keyboard::Right))
/// {
/// // move right...
/// }
/// \endcode
///
/// \see cpp3ds::Joystick, cpp3ds::Touch
///
////////////////////////////////////////////////////////////