-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Expand file tree
/
Copy pathinputKeyInfo.cpp
More file actions
114 lines (101 loc) · 3.28 KB
/
inputKeyInfo.cpp
File metadata and controls
114 lines (101 loc) · 3.28 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "input.h"
INPUT_KEY_INFO::INPUT_KEY_INFO(const WORD wVirtualKeyCode, const ULONG ulControlKeyState) :
_wVirtualKeyCode(wVirtualKeyCode),
_ulControlKeyState(ulControlKeyState)
{
}
INPUT_KEY_INFO::~INPUT_KEY_INFO() = default;
// Routine Description:
// - Gets the keyboard virtual key that was pressed.
// This represents the actual keyboard key, not the modifiers (unless only the modifier was pressed).
// Arguments:
// - <none>
// Return Value:
// - WORD value of key which can be matched to VK_ constants.
const WORD INPUT_KEY_INFO::GetVirtualKey() const
{
return _wVirtualKeyCode;
}
// Routine Description:
// - Specifies that the ctrl key was held when this particular input was received.
// Arguments:
// - <none>
// Return Value:
// - True if ctrl was held. False otherwise.
const bool INPUT_KEY_INFO::IsCtrlPressed() const
{
return (_ulControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) != 0;
}
// Routine Description:
// - Specifies that the alt key was held when this particular input was received.
// Arguments:
// - <none>
// Return Value:
// - True if alt was held. False otherwise.
const bool INPUT_KEY_INFO::IsAltPressed() const
{
return (_ulControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) != 0;
}
// Routine Description:
// - Specifies that the shift key was held when this particular input was received.
// Arguments:
// - <none>
// Return Value:
// - True if shift was held. False otherwise.
const bool INPUT_KEY_INFO::IsShiftPressed() const
{
return (_ulControlKeyState & (SHIFT_PRESSED)) != 0;
}
// Routine Description:
// - Helps determine if this key input represents a ctrl+KEY combo
// Arguments:
// - <none>
// Return Value:
// - True if control only, not shift nor alt. False otherwise.
const bool INPUT_KEY_INFO::IsCtrlOnly() const
{
return IsCtrlPressed() && !IsAltPressed() && !IsShiftPressed();
}
// Routine Description:
// - Helps determine if this key input represents a shift+KEY combo
// Arguments:
// - <none>
// Return Value:
// - True if shift only, not control nor alt. False otherwise.
const bool INPUT_KEY_INFO::IsShiftOnly() const
{
return !IsCtrlPressed() && !IsAltPressed() && IsShiftPressed();
}
// Routine Description:
// - Helps determine if this key input represents a shift+ctrl+KEY combo
// Arguments:
// - <none>
// Return Value:
// - True if shift and control but not alt. False otherwise.
const bool INPUT_KEY_INFO::IsShiftAndCtrlOnly() const
{
return IsCtrlPressed() && !IsAltPressed() && IsShiftPressed();
}
// Routine Description:
// - Helps determine if this key input represents an alt+KEY combo
// Arguments:
// - <none>
// Return Value:
// - True if alt but not shift or control. False otherwise.
const bool INPUT_KEY_INFO::IsAltOnly() const
{
return IsAltPressed() && !IsCtrlPressed() && !IsShiftPressed();
}
// Routine Description:
// - Determines if there's any modifier for this key
// Arguments:
// - <none>
// Return Value:
// - True if no Alt, Ctrl, or Shift modifier is in place.
const bool INPUT_KEY_INFO::HasNoModifiers() const
{
return !IsAltPressed() && !IsCtrlPressed() && !IsShiftPressed();
}