ReactOS 0.4.15-dev-5669-g09dde2c
RegisterHotKey.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for RegisterHotKey
5 * PROGRAMMERS: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8#include "precomp.h"
9
10#define msg_hotkey(msg, id, mod, vk) do \
11 { \
12 ok((msg)->message == WM_HOTKEY, "Unexpected message %u\n", (msg)->message); \
13 ok((msg)->hwnd == NULL, "hwnd = %p\n", (msg)->hwnd); \
14 ok((msg)->wParam == (id), "wParam = 0x%Ix\n", (msg)->wParam); \
15 ok((msg)->lParam == MAKELONG(mod, vk), \
16 "wParam = 0x%Ix, expected 0x%lx\n", (msg)->lParam, MAKELONG(mod, vk)); \
17 } while (0)
18#define expect_hotkey(id, mod, vk) do \
19 { \
20 MSG msg; \
21 int hotkey_count = 0; \
22 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) \
23 { \
24 msg_hotkey(&msg, id, mod, vk); \
25 if (msg.message == WM_HOTKEY) hotkey_count++; \
26 DispatchMessageW(&msg); \
27 } \
28 ok(hotkey_count == 1, "Received %d WM_HOTKEY messages, expected 1\n", hotkey_count); \
29 } while (0)
30#define msg_no_hotkey(msg) do \
31 { \
32 if ((msg)->message == WM_HOTKEY) \
33 ok((msg)->message != WM_HOTKEY, \
34 "Got WM_HOTKEY with hwnd=%p, wParam=0x%Ix, lParam=0x%Ix\n", \
35 (msg)->hwnd, (msg)->wParam, (msg)->lParam); \
36 else \
37 ok(0, \
38 "Unexpected message %u posted to thread with hwnd=%p, wParam=0x%Ix, lParam=0x%Ix\n", \
39 (msg)->message, (msg)->hwnd, (msg)->wParam, (msg)->lParam); \
40 } while (0)
41#define expect_no_hotkey() do \
42 { \
43 MSG msg; \
44 while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) \
45 { \
46 msg_no_hotkey(&msg); \
47 DispatchMessageW(&msg); \
48 } \
49 } while (0)
50
52{
53 SetCursorPos(0, 0);
54
59
61
62 trace("Ctrl only\n");
63 keybd_event(VK_CONTROL, 0, 0, 0);
67
68 trace("Ctrl+U\n");
69 keybd_event(VK_CONTROL, 0, 0, 0);
71 keybd_event('U', 0, 0, 0);
73 keybd_event('U', 0, KEYEVENTF_KEYUP, 0);
77
78 trace("Ctrl+U (with Ctrl up first)\n");
79 keybd_event(VK_CONTROL, 0, 0, 0);
81 keybd_event('U', 0, 0, 0);
85 keybd_event('U', 0, KEYEVENTF_KEYUP, 0);
87
88 trace("Ctrl+U (with U down first and Ctrl up first)\n");
89 keybd_event('U', 0, 0, 0);
91 keybd_event(VK_CONTROL, 0, 0, 0);
95 keybd_event('U', 0, KEYEVENTF_KEYUP, 0);
97
98 trace("Ctrl+U (with U down first and U up first)\n");
99 keybd_event('U', 0, 0, 0);
101 keybd_event(VK_CONTROL, 0, 0, 0);
103 keybd_event('U', 0, KEYEVENTF_KEYUP, 0);
107
108 trace("Ctrl+Alt\n");
109 keybd_event(VK_CONTROL, 0, 0, 0);
111 keybd_event(VK_MENU, 0, 0, 0);
117
118 trace("Ctrl+Alt (with Ctrl up first)\n");
119 keybd_event(VK_CONTROL, 0, 0, 0);
121 keybd_event(VK_MENU, 0, 0, 0);
127
128 trace("Alt+Ctrl\n");
129 keybd_event(VK_MENU, 0, 0, 0);
131 keybd_event(VK_CONTROL, 0, 0, 0);
137
138 trace("Alt+Ctrl (with Alt up first)\n");
139 keybd_event(VK_MENU, 0, 0, 0);
141 keybd_event(VK_CONTROL, 0, 0, 0);
147
148 trace("Alt+U\n");
149 keybd_event(VK_MENU, 0, 0, 0);
151 keybd_event('U', 0, 0, 0);
153 keybd_event('U', 0, KEYEVENTF_KEYUP, 0);
157
158 trace("Ctrl+Alt+U\n");
159 keybd_event(VK_CONTROL, 0, 0, 0);
161 keybd_event(VK_MENU, 0, 0, 0);
163 keybd_event('U', 0, 0, 0);
165 keybd_event('U', 0, KEYEVENTF_KEYUP, 0);
171
172 trace("Alt+Ctrl+U\n");
173 keybd_event(VK_MENU, 0, 0, 0);
175 keybd_event(VK_CONTROL, 0, 0, 0);
177 keybd_event('U', 0, 0, 0);
179 keybd_event('U', 0, KEYEVENTF_KEYUP, 0);
185
186 trace("Ctrl+U+Alt\n");
187 keybd_event(VK_CONTROL, 0, 0, 0);
189 keybd_event('U', 0, 0, 0);
190 expect_hotkey(2, MOD_CONTROL, 'U');
191 keybd_event(VK_MENU, 0, 0, 0);
195 keybd_event('U', 0, KEYEVENTF_KEYUP, 0);
199
200 trace("Alt+U+Ctrl\n");
201 keybd_event(VK_MENU, 0, 0, 0);
203 keybd_event('U', 0, 0, 0);
205 keybd_event(VK_CONTROL, 0, 0, 0);
209 keybd_event('U', 0, KEYEVENTF_KEYUP, 0);
213
214 /* The remaining combinations are an exercise left to the reader */
215
220
222}
#define expect_hotkey(id, mod, vk)
#define expect_no_hotkey()
#define trace
Definition: atltest.h:70
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define MOD_ALT
Definition: imm.h:319
#define MOD_CONTROL
Definition: imm.h:320
BOOL WINAPI UnregisterHotKey(_In_opt_ HWND, _In_ int)
#define VK_CONTROL
Definition: winuser.h:2193
BOOL WINAPI SetCursorPos(_In_ int, _In_ int)
Definition: cursoricon.c:2631
BOOL WINAPI RegisterHotKey(_In_opt_ HWND, _In_ int, _In_ UINT, _In_ UINT)
VOID WINAPI keybd_event(_In_ BYTE, _In_ BYTE, _In_ DWORD, _In_ ULONG_PTR)
#define KEYEVENTF_KEYUP
Definition: winuser.h:1096
#define VK_MENU
Definition: winuser.h:2194