Ocean
Keyboard.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_PLATFORM_KEYBOARD_H
9 #define META_OCEAN_PLATFORM_KEYBOARD_H
10 
12 
13 namespace Ocean
14 {
15 
16 namespace Platform
17 {
18 
19 /**
20  * This class implements keyboard functionalities.
21  * Not available on the following platforms: Android, IOS.
22  * @ingroup platform
23  */
24 class OCEAN_PLATFORM_EXPORT Keyboard
25 {
26  public:
27 
28  /**
29  * Definition of individual keyboard keys.
30  */
31  enum Key
32  {
33  /// No key.
34  KEY_NONE = 0,
35  /// The left shift key.
36  KEY_SHIFT_LEFT = (1 << 0),
37  /// The right shift key.
38  KEY_SHIFT_RIGHT = (1 << 1),
39  /// The left control key.
40  KEY_CONTROL_LEFT = (1 << 2),
41  /// The right control key.
42  KEY_CONTROL_RIGHT = (1 << 3),
43  /// The left menu key.
44  KEY_MENU_LEFT = (1 << 4),
45  /// The right menu key.
46  KEY_MENU_RIGHT = (1 << 5),
47  /// The space key.
48  KEY_SPACE = (1 << 6),
49  /// Last key value.
50  KEY_LAST_UNIQUE_VALUE = (1 << 6),
51  /// Both shift keys (left and right), beware: is not a unique (single) key.
52  KEY_SHIFT = KEY_SHIFT_LEFT | KEY_SHIFT_RIGHT,
53  /// Both control keys (left and right), beware: is not a unique (single) key.
54  KEY_CONTROL = KEY_CONTROL_LEFT | KEY_CONTROL_RIGHT,
55  /// Both menu keys (left and right), beware: is not a unique (single) key.
56  KEY_MENU = KEY_MENU_LEFT | KEY_MENU_RIGHT,
57  };
58 
59  public:
60 
61  /**
62  * Returns whether all specified keys of the keyboard are currently pushed (down) or not.
63  * @param keys The keys for that the states are requested (may be a combination of several keys)
64  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
65  * @return True, if so; also True if no key is provided
66  */
67  static bool allKeysDown(const Key keys, const bool synchron = true);
68 
69  /**
70  * Returns whether at least one key of the specified keys of the keyboard is currently pushed (down) or not.
71  * @param keys The keys for that the states are requested (may be a combination of several keys)
72  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
73  * @return True, if so; also True if no key is provided
74  */
75  static bool oneKeyDown(const Key keys, const bool synchron = true);
76 
77  /**
78  * Returns whether exactly one (specified key) is currently pushed (down) or not.
79  * @param key One unique key for that the state is requested, must not be a combination of several keys
80  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
81  * @return True, if so
82  */
83  static bool isKeyDown(const Key key, const bool synchron = true);
84 
85  /**
86  * Returns the current key state for the shift, control and menu keys.
87  * This function does not distinguish between the left and a right key version.
88  * @return Current key state
89  */
90  static Key currentKeyState(const bool synchron = true);
91 
92  protected:
93 
94 #if defined(_WINDOWS)
95 
96  /**
97  * Returns whether exactly one (specified key) is currently pushed (down) or not (specialization for Windows)
98  * @sa isKeyDown()
99  * @param key One unique key for that the state is requested, must not be a combination of several keys
100  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
101  * @return True, if so
102  */
103  static bool isKeyDownWindows(const Key key, const bool synchron = true);
104 
105  /**
106  * Returns whether exactly one (specified key) is currently pushed (down) or not.
107  * @param nVirtualKey The virtual key code for that the state is requested
108  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
109  * @return True, if so
110  */
111  static bool keyStateWindows(const int nVirtualKey, const bool synchron);
112 
113 #elif defined(__APPLE__)
114 
115  /**
116  * Returns whether exactly one (specified key) is currently pushed (down) or not (specialization for Apple platforms)
117  * @sa isKeyDown()
118  * @param key One unique key for that the state is requested, must not be a combination of several keys
119  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
120  * @return True, if so
121  */
122  static bool isKeyDownApple(const Key key, const bool synchron = true);
123 
124  /**
125  * Returns whether exactly one (specified key) is currently pushed (down) or not.
126  * @param nVirtualKey The virtual key code for that the state is requested
127  * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
128  * @return True, if so
129  */
130  static bool keyStateApple(const unsigned short nVirtualKey, const bool synchron);
131 
132 #endif
133 
134 };
135 
136 }
137 
138 }
139 
140 #endif // META_OCEAN_PLATFORM_KEYBOARD_H
This class implements keyboard functionalities.
Definition: Keyboard.h:25
static Key currentKeyState(const bool synchron=true)
Returns the current key state for the shift, control and menu keys.
static bool keyStateWindows(const int nVirtualKey, const bool synchron)
Returns whether exactly one (specified key) is currently pushed (down) or not.
static bool isKeyDownWindows(const Key key, const bool synchron=true)
Returns whether exactly one (specified key) is currently pushed (down) or not (specialization for Win...
Key
Definition of individual keyboard keys.
Definition: Keyboard.h:32
static bool oneKeyDown(const Key keys, const bool synchron=true)
Returns whether at least one key of the specified keys of the keyboard is currently pushed (down) or ...
static bool isKeyDownApple(const Key key, const bool synchron=true)
Returns whether exactly one (specified key) is currently pushed (down) or not (specialization for App...
static bool isKeyDown(const Key key, const bool synchron=true)
Returns whether exactly one (specified key) is currently pushed (down) or not.
static bool allKeysDown(const Key keys, const bool synchron=true)
Returns whether all specified keys of the keyboard are currently pushed (down) or not.
static bool keyStateApple(const unsigned short nVirtualKey, const bool synchron)
Returns whether exactly one (specified key) is currently pushed (down) or not.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15