Ocean
Loading...
Searching...
No Matches
win/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_WIN_KEYBOARD_H
9#define META_OCEAN_PLATFORM_WIN_KEYBOARD_H
10
12
14
15namespace Ocean
16{
17
18namespace Platform
19{
20
21namespace Win
22{
23
24/**
25 * This class implements keyboard functionalities.
26 * @ingroup platformwin
27 */
28class OCEAN_PLATFORM_WIN_EXPORT Keyboard : Platform::Keyboard
29{
30 public:
31
32 /**
33 * Translates a virtual key code to the corresponsing character key and key description.
34 * @param vKey Virtual key code to translate
35 * @param key Resulting key character or name
36 * @return True, if succeeded
37 */
38 static bool translateVirtualkey(const unsigned int vKey, std::string& key);
39
40 /**
41 * Returns whether all specified keys of the keyboard are currently pushed (down) or not.
42 * @param keys The keys for that the states are requested (may be a combination of several keys)
43 * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
44 * @return True, if so; also True if no key is provided
45 */
46 static bool allKeysDown(const Key keys, const bool synchron = true);
47
48 /**
49 * Returns whether at least one key of the specified keys of the keyboard is currently pushed (down) or not.
50 * @param keys The keys for that the states are requested (may be a combination of several keys)
51 * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
52 * @return True, if so; also True if no key is provided
53 */
54 static bool oneKeyDown(const Key keys, const bool synchron = true);
55
56 /**
57 * Returns wheater exactly one (specified key) is currently pushed (down) or not.
58 * @param key One unique key for that the state is requested, must not be a combination of several keys
59 * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
60 * @return True, if so
61 */
62 static bool isKeyDown(const Key key, const bool synchron = true);
63
64 /**
65 * Returns the current key state for the shift, control and menu keys.
66 * This function does not distinguish between the left and a right key version.
67 * @return Current key state
68 */
69 static Key currentKeyState(const bool synchron = true);
70
71 protected:
72
73 /**
74 * Returns wheater exactly one (specified key) is currently pushed (down) or not.
75 * @param nVirtualKey The virtual key code for that the state is requested
76 * @param synchron True, to request the state synchronously with the message queue; False, to request the state in the current moment
77 * @return True, if so
78 */
79 static inline bool keyState(const int nVirtualKey, const bool synchron);
80};
81
82inline bool Keyboard::keyState(const int nVirtualKey, const bool synchron)
83{
84 if (synchron)
85 {
86 // MSDN: If the high-order bit is 1, the key is down; otherwise, it is up
87 return (GetKeyState(nVirtualKey) & 0xF0) != 0;
88 }
89 else
90 {
91 return GetAsyncKeyState(nVirtualKey) != 0;
92 }
93}
94
95}
96
97}
98
99}
100
101#endif // META_OCEAN_PLATFORM_WIN_KEYBOARD_H
This class implements keyboard functionalities.
Definition Keyboard.h:25
Key
Definition of individual keyboard keys.
Definition Keyboard.h:32
This class implements keyboard functionalities.
Definition win/Keyboard.h:29
static bool keyState(const int nVirtualKey, const bool synchron)
Returns wheater exactly one (specified key) is currently pushed (down) or not.
Definition win/Keyboard.h:82
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 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 isKeyDown(const Key key, const bool synchron=true)
Returns wheater exactly one (specified key) is currently pushed (down) or not.
static Key currentKeyState(const bool synchron=true)
Returns the current key state for the shift, control and menu keys.
static bool translateVirtualkey(const unsigned int vKey, std::string &key)
Translates a virtual key code to the corresponsing character key and key description.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15