Skip to content

Commit 2a64348

Browse files
committed
chore: optimize the SendKey function Bush2021/chrome_plus@72c9398
1 parent d028573 commit 2a64348

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/utils.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,14 @@ void SendKey(T&&... keys) {
304304
switch (key) {
305305
case VK_RBUTTON:
306306
input.type = INPUT_MOUSE;
307-
input.mi.dwFlags = ::GetSystemMetrics(SM_SWAPBUTTON) == TRUE
307+
input.mi.dwFlags = GetSystemMetrics(SM_SWAPBUTTON) == TRUE
308308
? MOUSEEVENTF_LEFTDOWN
309309
: MOUSEEVENTF_RIGHTDOWN;
310310
input.mi.dwExtraInfo = MAGIC_CODE;
311311
break;
312312
case VK_LBUTTON:
313313
input.type = INPUT_MOUSE;
314-
input.mi.dwFlags = ::GetSystemMetrics(SM_SWAPBUTTON) == TRUE
314+
input.mi.dwFlags = GetSystemMetrics(SM_SWAPBUTTON) == TRUE
315315
? MOUSEEVENTF_RIGHTDOWN
316316
: MOUSEEVENTF_LEFTDOWN;
317317
input.mi.dwExtraInfo = MAGIC_CODE;
@@ -324,26 +324,26 @@ void SendKey(T&&... keys) {
324324
default:
325325
input.type = INPUT_KEYBOARD;
326326
input.ki.wVk = (WORD)key;
327+
input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
327328
input.ki.dwExtraInfo = MAGIC_CODE;
328329
break;
329330
}
330-
input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY;
331331
inputs.emplace_back(std::move(input));
332332
}
333-
for (auto& key = keys_.begin(); key != keys_.end(); ++key) {
333+
for (auto& key : keys_) {
334334
INPUT input = {0};
335335
// 修正鼠标消息
336-
switch (*key) {
336+
switch (key) {
337337
case VK_RBUTTON:
338338
input.type = INPUT_MOUSE;
339-
input.mi.dwFlags = ::GetSystemMetrics(SM_SWAPBUTTON) == TRUE
339+
input.mi.dwFlags = GetSystemMetrics(SM_SWAPBUTTON) == TRUE
340340
? MOUSEEVENTF_LEFTUP
341341
: MOUSEEVENTF_RIGHTUP;
342342
input.mi.dwExtraInfo = MAGIC_CODE;
343343
break;
344344
case VK_LBUTTON:
345345
input.type = INPUT_MOUSE;
346-
input.mi.dwFlags = ::GetSystemMetrics(SM_SWAPBUTTON) == TRUE
346+
input.mi.dwFlags = GetSystemMetrics(SM_SWAPBUTTON) == TRUE
347347
? MOUSEEVENTF_RIGHTUP
348348
: MOUSEEVENTF_LEFTUP;
349349
input.mi.dwExtraInfo = MAGIC_CODE;
@@ -356,14 +356,14 @@ void SendKey(T&&... keys) {
356356
default:
357357
input.type = INPUT_KEYBOARD;
358358
input.ki.dwFlags = KEYEVENTF_KEYUP;
359-
input.ki.wVk = (WORD)(*key);
359+
input.ki.wVk = (WORD)key;
360+
input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP;
360361
input.ki.dwExtraInfo = MAGIC_CODE;
361362
break;
362363
}
363-
input.ki.dwFlags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP;
364364
inputs.emplace_back(std::move(input));
365365
}
366-
::SendInput((UINT)inputs.size(), &inputs[0], sizeof(INPUT));
366+
SendInput((UINT)inputs.size(), &inputs[0], sizeof(INPUT));
367367
}
368368

369369
// 发送鼠标消息

0 commit comments

Comments
 (0)