MCPcopy Create free account
hub / github.com/WallBreaker2/op / KeyUp

Method KeyUp

libop/input/keyboard/WinKeyboard.cpp:164–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164long WinKeyboard::KeyUp(long vk_code) {
165 long ret = 0;
166 // vk_code = toupper(vk_code);
167 switch (_mode) {
168 case INPUT_TYPE::IN_NORMAL: {
169
170 INPUT Input = {0};
171 Input.type = INPUT_KEYBOARD;
172 Input.ki.wVk = static_cast<WORD>(vk_code);
173 Input.ki.wScan = 0;
174 Input.ki.dwFlags = KEYEVENTF_KEYUP;
175
176 /*The function returns the number of events that it successfully inserted into the keyboard or mouse input
177 stream. If the function returns zero, the input was already blocked by another thread. To get extended error
178 information, call GetLastError. This function fails when it is blocked by UIPI. Note that neither GetLastError
179 nor the return value will indicate the failure was caused by UIPI blocking.
180 */
181 ret = ::SendInput(1, &Input, sizeof(INPUT));
182 break;
183 }
184 case INPUT_TYPE::IN_NORMAL2: {
185 INPUT Input = {0};
186 Input.type = INPUT_KEYBOARD;
187 Input.ki.wVk = 0;
188 Input.ki.wScan = MapVirtualKey(vk_code, MAPVK_VK_TO_VSC);
189 Input.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
190 // 抬键时保持和按下阶段一致的扩展键标志。
191 if (key_message::IsExtendedVirtualKey(static_cast<UINT>(vk_code)))
192 Input.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
193 ret = ::SendInput(1, &Input, sizeof(INPUT));
194 if (ret == 0)
195 setlog("op:IN_NORMAL2 erro code:%s", GetLastErrorAsString().c_str());
196 break;
197 }
198
199 case INPUT_TYPE::IN_WINDOWS: {
200 // 抬键时保持和按下阶段一致的消息类型与 lParam 位语义。
201 const bool use_system_message = is_alt_vk(vk_code) || _alt_down;
202 const bool alt_context = _alt_down && !is_alt_vk(vk_code);
203 const UINT message = use_system_message ? WM_SYSKEYUP : WM_KEYUP;
204 const LPARAM lparam = key_message::BuildKeyLParam(static_cast<UINT>(vk_code), true, alt_context);
205
206 ret = message::SendTimeout(_hwnd, message, vk_code, lparam);
207 if (ret == 0)
208 setlog("error code=%d", GetLastError());
209 else {
210 if (is_shift_vk(vk_code))
211 _shift_down = false;
212 else if (is_ctrl_vk(vk_code))
213 _ctrl_down = false;
214 else if (is_alt_vk(vk_code))
215 _alt_down = false;
216 }
217 break;
218 }
219 }
220
221 return ret;

Callers

nothing calls this directly

Calls 8

IsExtendedVirtualKeyFunction · 0.85
setlogFunction · 0.85
GetLastErrorAsStringFunction · 0.85
is_alt_vkFunction · 0.85
BuildKeyLParamFunction · 0.85
SendTimeoutFunction · 0.85
is_shift_vkFunction · 0.85
is_ctrl_vkFunction · 0.85

Tested by

no test coverage detected