forked from microsoft/terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyEvent.cpp
More file actions
179 lines (162 loc) · 4.25 KB
/
Copy pathKeyEvent.cpp
File metadata and controls
179 lines (162 loc) · 4.25 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "precomp.h"
#include "inc/IInputEvent.hpp"
KeyEvent::~KeyEvent()
{
}
INPUT_RECORD KeyEvent::ToInputRecord() const noexcept
{
INPUT_RECORD record{ 0 };
record.EventType = KEY_EVENT;
record.Event.KeyEvent.bKeyDown = !!_keyDown;
record.Event.KeyEvent.wRepeatCount = _repeatCount;
record.Event.KeyEvent.wVirtualKeyCode = _virtualKeyCode;
record.Event.KeyEvent.wVirtualScanCode = _virtualScanCode;
record.Event.KeyEvent.uChar.UnicodeChar = _charData;
record.Event.KeyEvent.dwControlKeyState = _activeModifierKeys;
return record;
}
InputEventType KeyEvent::EventType() const noexcept
{
return InputEventType::KeyEvent;
}
void KeyEvent::SetKeyDown(const bool keyDown) noexcept
{
_keyDown = keyDown;
}
void KeyEvent::SetRepeatCount(const WORD repeatCount) noexcept
{
_repeatCount = repeatCount;
}
void KeyEvent::SetVirtualKeyCode(const WORD virtualKeyCode) noexcept
{
_virtualKeyCode = virtualKeyCode;
}
void KeyEvent::SetVirtualScanCode(const WORD virtualScanCode) noexcept
{
_virtualScanCode = virtualScanCode;
}
void KeyEvent::SetCharData(const wchar_t character) noexcept
{
_charData = character;
}
void KeyEvent::SetActiveModifierKeys(const DWORD activeModifierKeys) noexcept
{
_activeModifierKeys = activeModifierKeys;
}
void KeyEvent::DeactivateModifierKey(const ModifierKeyState modifierKey) noexcept
{
DWORD const bitFlag = ToConsoleControlKeyFlag(modifierKey);
WI_ClearAllFlags(_activeModifierKeys, bitFlag);
}
void KeyEvent::ActivateModifierKey(const ModifierKeyState modifierKey) noexcept
{
DWORD const bitFlag = ToConsoleControlKeyFlag(modifierKey);
WI_SetAllFlags(_activeModifierKeys, bitFlag);
}
bool KeyEvent::DoActiveModifierKeysMatch(const std::unordered_set<ModifierKeyState>& consoleModifiers) const noexcept
{
DWORD consoleBits = 0;
for (const ModifierKeyState& mod : consoleModifiers)
{
WI_SetAllFlags(consoleBits, ToConsoleControlKeyFlag(mod));
}
return consoleBits == _activeModifierKeys;
}
// Routine Description:
// - checks if this key event is a special key for line editing
// Arguments:
// - none
// Return Value:
// - true if this key has special relevance to line editing, false otherwise
bool KeyEvent::IsCommandLineEditingKey() const noexcept
{
if (!IsAltPressed() && !IsCtrlPressed())
{
switch (GetVirtualKeyCode())
{
case VK_ESCAPE:
case VK_PRIOR:
case VK_NEXT:
case VK_END:
case VK_HOME:
case VK_LEFT:
case VK_UP:
case VK_RIGHT:
case VK_DOWN:
case VK_INSERT:
case VK_DELETE:
case VK_F1:
case VK_F2:
case VK_F3:
case VK_F4:
case VK_F5:
case VK_F6:
case VK_F7:
case VK_F8:
case VK_F9:
return true;
default:
break;
}
}
if (IsCtrlPressed())
{
switch (GetVirtualKeyCode())
{
case VK_END:
case VK_HOME:
case VK_LEFT:
case VK_RIGHT:
return true;
default:
break;
}
}
if (IsAltPressed())
{
switch (GetVirtualKeyCode())
{
case VK_F7:
case VK_F10:
return true;
default:
break;
}
}
return false;
}
// Routine Description:
// - checks if this key event is a special key for popups
// Arguments:
// - None
// Return Value:
// - true if this key has special relevance to popups, false otherwise
bool KeyEvent::IsPopupKey() const noexcept
{
if (!IsAltPressed() && !IsCtrlPressed())
{
switch (GetVirtualKeyCode())
{
case VK_ESCAPE:
case VK_PRIOR:
case VK_NEXT:
case VK_END:
case VK_HOME:
case VK_LEFT:
case VK_UP:
case VK_RIGHT:
case VK_DOWN:
case VK_F2:
case VK_F4:
case VK_F7:
case VK_F9:
case VK_DELETE:
return true;
default:
break;
}
}
return false;
}