Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223/* * PROJECT: ReactOS API tests * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory * PURPOSE: Test for RegisterHotKey * PROGRAMMERS: Thomas Faber <thomas.faber@reactos.org> */
#include "precomp.h"
#define msg_hotkey(msg, id, mod, vk) do \ { \ ok((msg)->message == WM_HOTKEY, "Unexpected message %u\n", (msg)->message); \ ok((msg)->hwnd == NULL, "hwnd = %p\n", (msg)->hwnd); \ ok((msg)->wParam == (id), "wParam = 0x%Ix\n", (msg)->wParam); \ ok((msg)->lParam == MAKELONG(mod, vk), \ "wParam = 0x%Ix, expected 0x%lx\n", (msg)->lParam, MAKELONG(mod, vk)); \ } while (0)#define expect_hotkey(id, mod, vk) do \ { \ MSG msg; \ int hotkey_count = 0; \ while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) \ { \ msg_hotkey(&msg, id, mod, vk); \ if (msg.message == WM_HOTKEY) hotkey_count++; \ DispatchMessageW(&msg); \ } \ ok(hotkey_count == 1, "Received %d WM_HOTKEY messages, expected 1\n", hotkey_count); \ } while (0)#define msg_no_hotkey(msg) do \ { \ if ((msg)->message == WM_HOTKEY) \ ok((msg)->message != WM_HOTKEY, \ "Got WM_HOTKEY with hwnd=%p, wParam=0x%Ix, lParam=0x%Ix\n", \ (msg)->hwnd, (msg)->wParam, (msg)->lParam); \ else \ ok(0, \ "Unexpected message %u posted to thread with hwnd=%p, wParam=0x%Ix, lParam=0x%Ix\n", \ (msg)->message, (msg)->hwnd, (msg)->wParam, (msg)->lParam); \ } while (0)#define expect_no_hotkey() do \ { \ MSG msg; \ while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) \ { \ msg_no_hotkey(&msg); \ DispatchMessageW(&msg); \ } \ } while (0)
START_TEST(RegisterHotKey){ SetCursorPos(0, 0);
RegisterHotKey(NULL, 1, MOD_CONTROL, 0); RegisterHotKey(NULL, 2, MOD_CONTROL, 'U'); RegisterHotKey(NULL, 3, MOD_CONTROL | MOD_ALT, 0); RegisterHotKey(NULL, 4, MOD_CONTROL | MOD_ALT, 'U');
expect_no_hotkey();
trace("Ctrl only\n"); keybd_event(VK_CONTROL, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); expect_hotkey(1, 0, VK_CONTROL);
trace("Ctrl+U\n"); keybd_event(VK_CONTROL, 0, 0, 0); expect_no_hotkey(); keybd_event('U', 0, 0, 0); expect_hotkey(2, MOD_CONTROL, 'U'); keybd_event('U', 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey();
trace("Ctrl+U (with Ctrl up first)\n"); keybd_event(VK_CONTROL, 0, 0, 0); expect_no_hotkey(); keybd_event('U', 0, 0, 0); expect_hotkey(2, MOD_CONTROL, 'U'); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey(); keybd_event('U', 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey();
trace("Ctrl+U (with U down first and Ctrl up first)\n"); keybd_event('U', 0, 0, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); expect_hotkey(1, 0, VK_CONTROL); keybd_event('U', 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey();
trace("Ctrl+U (with U down first and U up first)\n"); keybd_event('U', 0, 0, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, 0, 0); expect_no_hotkey(); keybd_event('U', 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey();
trace("Ctrl+Alt\n"); keybd_event(VK_CONTROL, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_MENU, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); expect_hotkey(3, MOD_CONTROL, VK_MENU); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey();
trace("Ctrl+Alt (with Ctrl up first)\n"); keybd_event(VK_CONTROL, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_MENU, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); expect_hotkey(3, MOD_ALT, VK_CONTROL); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey();
trace("Alt+Ctrl\n"); keybd_event(VK_MENU, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); expect_hotkey(3, MOD_ALT, VK_CONTROL); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey();
trace("Alt+Ctrl (with Alt up first)\n"); keybd_event(VK_MENU, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); expect_hotkey(3, MOD_CONTROL, VK_MENU); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey();
trace("Alt+U\n"); keybd_event(VK_MENU, 0, 0, 0); expect_no_hotkey(); keybd_event('U', 0, 0, 0); expect_no_hotkey(); keybd_event('U', 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey(); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey();
trace("Ctrl+Alt+U\n"); keybd_event(VK_CONTROL, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_MENU, 0, 0, 0); expect_no_hotkey(); keybd_event('U', 0, 0, 0); expect_hotkey(4, MOD_CONTROL | MOD_ALT, 'U'); keybd_event('U', 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey(); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey();
trace("Alt+Ctrl+U\n"); keybd_event(VK_MENU, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, 0, 0); expect_no_hotkey(); keybd_event('U', 0, 0, 0); expect_hotkey(4, MOD_CONTROL | MOD_ALT, 'U'); keybd_event('U', 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey(); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey();
trace("Ctrl+U+Alt\n"); keybd_event(VK_CONTROL, 0, 0, 0); expect_no_hotkey(); keybd_event('U', 0, 0, 0); expect_hotkey(2, MOD_CONTROL, 'U'); keybd_event(VK_MENU, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); expect_hotkey(3, MOD_CONTROL, VK_MENU); keybd_event('U', 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey();
trace("Alt+U+Ctrl\n"); keybd_event(VK_MENU, 0, 0, 0); expect_no_hotkey(); keybd_event('U', 0, 0, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, 0, 0); expect_no_hotkey(); keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); expect_hotkey(3, MOD_ALT, VK_CONTROL); keybd_event('U', 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey(); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); expect_no_hotkey();
/* The remaining combinations are an exercise left to the reader */
UnregisterHotKey(NULL, 4); UnregisterHotKey(NULL, 3); UnregisterHotKey(NULL, 2); UnregisterHotKey(NULL, 1);
expect_no_hotkey();}