summaryrefslogtreecommitdiffstats
path: root/chrome_frame/test/chrome_frame_test_utils.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome_frame/test/chrome_frame_test_utils.cc')
-rw-r--r--chrome_frame/test/chrome_frame_test_utils.cc24
1 files changed, 15 insertions, 9 deletions
diff --git a/chrome_frame/test/chrome_frame_test_utils.cc b/chrome_frame/test/chrome_frame_test_utils.cc
index 4912901..54d18de 100644
--- a/chrome_frame/test/chrome_frame_test_utils.cc
+++ b/chrome_frame/test/chrome_frame_test_utils.cc
@@ -114,29 +114,35 @@ END_MSG_MAP()
if (NULL == Create(NULL, NULL, NULL, WS_POPUP))
return AtlHresultFromLastError();
- static const int hotkey_id = 0x0000baba;
+ static const int kHotKeyId = 0x0000baba;
+ static const int kHotKeyWaitTimeout = 2000;
SetWindowLongPtr(GWLP_USERDATA, reinterpret_cast<ULONG_PTR>(window));
- RegisterHotKey(m_hWnd, hotkey_id, 0, VK_F22);
+ RegisterHotKey(m_hWnd, kHotKeyId, 0, VK_F22);
MSG msg = {0};
PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
- INPUT hotkey = {0};
- hotkey.type = INPUT_KEYBOARD;
- hotkey.ki.wVk = VK_F22;
- SendInput(1, &hotkey, sizeof(hotkey));
+ SendVirtualKey(VK_F22, false);
+ // There are scenarios where the WM_HOTKEY is not dispatched by the
+ // the corresponding foreground thread. To prevent us from indefinitely
+ // waiting for the hotkey, we set a timer and exit the loop.
+ SetTimer(kHotKeyId, kHotKeyWaitTimeout, NULL);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
- if (WM_HOTKEY == msg.message)
+ if (msg.message == WM_HOTKEY)
break;
+ else if (msg.message == WM_TIMER) {
+ SetForegroundWindow(window);
+ break;
+ }
}
- UnregisterHotKey(m_hWnd, hotkey_id);
+ UnregisterHotKey(m_hWnd, kHotKeyId);
+ KillTimer(kHotKeyId);
DestroyWindow();
-
return S_OK;
}