ReactOS 0.4.16-dev-1214-gd663eb4
hotkey.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _HOT_KEY
 

Macros

#define IDHK_F12   -5
 
#define IDHK_SHIFTF12   -6
 
#define IDHK_WINKEY   -7
 
#define IDHK_WNDKEY   -8 /* WM_SETHOTKEY */
 
#define IDHK_SNAP_LEFT   -10
 
#define IDHK_SNAP_RIGHT   -11
 
#define IDHK_SNAP_UP   -12
 
#define IDHK_SNAP_DOWN   -13
 

Typedefs

typedef struct _HOT_KEY HOT_KEY
 
typedef struct _HOT_KEYPHOT_KEY
 

Functions

VOID FASTCALL UnregisterWindowHotKeys (PWND Window)
 
VOID FASTCALL UnregisterThreadHotKeys (PTHREADINFO pti)
 
BOOL NTAPI co_UserProcessHotKeys (WORD wVk, BOOL bIsDown)
 
UINT FASTCALL DefWndGetHotKey (PWND pWnd)
 
INT FASTCALL DefWndSetHotKey (PWND pWnd, WPARAM wParam)
 
VOID FASTCALL StartDebugHotKeys (VOID)
 
BOOL FASTCALL UserRegisterHotKey (PWND pWnd, int id, UINT fsModifiers, UINT vk)
 
BOOL FASTCALL UserUnregisterHotKey (PWND pWnd, int id)
 

Macro Definition Documentation

◆ IDHK_F12

#define IDHK_F12   -5

Definition at line 14 of file hotkey.h.

◆ IDHK_SHIFTF12

#define IDHK_SHIFTF12   -6

Definition at line 15 of file hotkey.h.

◆ IDHK_SNAP_DOWN

#define IDHK_SNAP_DOWN   -13

Definition at line 23 of file hotkey.h.

◆ IDHK_SNAP_LEFT

#define IDHK_SNAP_LEFT   -10

Definition at line 20 of file hotkey.h.

◆ IDHK_SNAP_RIGHT

#define IDHK_SNAP_RIGHT   -11

Definition at line 21 of file hotkey.h.

◆ IDHK_SNAP_UP

#define IDHK_SNAP_UP   -12

Definition at line 22 of file hotkey.h.

◆ IDHK_WINKEY

#define IDHK_WINKEY   -7

Definition at line 16 of file hotkey.h.

◆ IDHK_WNDKEY

#define IDHK_WNDKEY   -8 /* WM_SETHOTKEY */

Definition at line 17 of file hotkey.h.

Typedef Documentation

◆ HOT_KEY

◆ PHOT_KEY

Function Documentation

◆ co_UserProcessHotKeys()

BOOL NTAPI co_UserProcessHotKeys ( WORD  wVk,
BOOL  bIsDown 
)

Definition at line 191 of file hotkey.c.

192{
193 UINT fModifiers;
194 PHOT_KEY pHotKey;
195 PWND pWnd;
196 BOOL DoNotPostMsg = FALSE;
197 BOOL IsModifier = FALSE;
198
199 if (wVk == VK_SHIFT || wVk == VK_CONTROL || wVk == VK_MENU ||
200 wVk == VK_LWIN || wVk == VK_RWIN)
201 {
202 /* Remember that this was a modifier */
203 IsModifier = TRUE;
204 }
205
206 fModifiers = IntGetModifiers(gafAsyncKeyState);
207
208 if (bIsDown)
209 {
210 if (IsModifier)
211 {
212 /* Modifier key down -- no hotkey trigger, but remember this */
213 gfsModOnlyCandidate = fModifiers;
214 return FALSE;
215 }
216 else
217 {
218 /* Regular key down -- check for hotkey, and reset mod candidates */
219 pHotKey = IsHotKey(fModifiers, wVk);
221 }
222 }
223 else
224 {
225 if (IsModifier)
226 {
227 /* Modifier key up -- modifier-only keys are triggered here */
228 pHotKey = IsHotKey(gfsModOnlyCandidate, 0);
230 }
231 else
232 {
233 /* Regular key up -- no hotkey, but reset mod-only candidates */
235 return FALSE;
236 }
237 }
238
239 if (pHotKey)
240 {
241 TRACE("Hot key pressed (pWnd %p, id %d)\n", pHotKey->pWnd, pHotKey->id);
242
243 /* FIXME: See comment about "UserDebuggerHotKey" on top of this file. */
244 if (pHotKey->id == IDHK_SHIFTF12 || pHotKey->id == IDHK_F12)
245 {
246 if (bIsDown)
247 {
248 ERR("Hot key pressed for Debug Activation! ShiftF12 = %d or F12 = %d\n",pHotKey->id == IDHK_SHIFTF12 , pHotKey->id == IDHK_F12);
249 //DoNotPostMsg = co_ActivateDebugger(); // FIXME
250 }
251 return DoNotPostMsg;
252 }
253
254 /* WIN and F12 keys are not hardcoded here. See comments on top of this file. */
255 if (pHotKey->id == IDHK_WINKEY)
256 {
257 ASSERT(!bIsDown);
259 if (pWnd)
260 {
261 TRACE("System Hot key Id %d Key %u\n", pHotKey->id, wVk );
263 co_IntShellHookNotify(HSHELL_TASKMAN, 0, 0);
264 return FALSE;
265 }
266 }
267
268 if (pHotKey->id == IDHK_SNAP_LEFT ||
269 pHotKey->id == IDHK_SNAP_RIGHT ||
270 pHotKey->id == IDHK_SNAP_UP ||
271 pHotKey->id == IDHK_SNAP_DOWN)
272 {
273 HWND topWnd = UserGetForegroundWindow();
274 if (topWnd)
275 {
276 UserPostMessage(topWnd, WM_KEYDOWN, wVk, 0);
277 }
278 return TRUE;
279 }
280
281 if (!pHotKey->pWnd)
282 {
283 TRACE("UPTM Hot key Id %d Key %u\n", pHotKey->id, wVk );
284 UserPostThreadMessage(pHotKey->pti, WM_HOTKEY, pHotKey->id, MAKELONG(fModifiers, wVk));
285 //ptiLastInput = pHotKey->pti;
286 return TRUE; /* Don't send any message */
287 }
288 else
289 {
290 pWnd = pHotKey->pWnd;
291 if (pWnd == PWND_BOTTOM)
292 {
293 if (gpqForeground == NULL)
294 return FALSE;
295
297 }
298
299 if (pWnd)
300 {
301 // pWnd->head.rpdesk->pDeskInfo->spwndShell needs testing.
303 {
305 co_IntShellHookNotify(HSHELL_TASKMAN, 0, 0);
306 }
307 else if (IsWindowHotKey(pHotKey))
308 {
309 /* WM_SETHOTKEY notifies with WM_SYSCOMMAND, not WM_HOTKEY */
310 if (bIsDown)
311 {
316 }
317 }
318 else
319 {
320 TRACE("UPM Hot key Id %d Key %u\n", pHotKey->id, wVk );
321 UserPostMessage(UserHMGetHandle(pWnd), WM_HOTKEY, pHotKey->id, MAKELONG(fModifiers, wVk));
322 }
323 //ptiLastInput = pWnd->head.pti;
324 return TRUE; /* Don't send any message */
325 }
326 }
327 }
328 return FALSE;
329}
#define ERR(fmt,...)
Definition: precomp.h:57
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
PUSER_MESSAGE_QUEUE gpqForeground
Definition: focus.c:13
HWND FASTCALL UserGetForegroundWindow(VOID)
Definition: focus.c:1424
#define IDHK_SNAP_LEFT
Definition: hotkey.h:20
#define IDHK_WINKEY
Definition: hotkey.h:16
#define IDHK_SNAP_UP
Definition: hotkey.h:22
#define IDHK_F12
Definition: hotkey.h:14
#define IDHK_SNAP_DOWN
Definition: hotkey.h:23
#define IDHK_SNAP_RIGHT
Definition: hotkey.h:21
#define IDHK_SHIFTF12
Definition: hotkey.h:15
#define UserHMGetHandle(obj)
Definition: ntuser.h:230
#define PWND_BOTTOM
Definition: ntuser.h:769
#define ASSERT(a)
Definition: mode.c:44
unsigned int UINT
Definition: ndis.h:50
PWINSTATION_OBJECT InputWindowStation
Definition: winsta.c:21
#define TRACE(s)
Definition: solgame.cpp:4
Definition: hotkey.h:4
PTHREADINFO pti
Definition: hotkey.h:5
INT id
Definition: hotkey.h:9
PWND pWnd
Definition: hotkey.h:6
HANDLE ShellWindow
Definition: winsta.h:43
Definition: ntuser.h:694
#define MAKELONG(a, b)
Definition: typedefs.h:249
#define ValidateHwndNoErr(hwnd)
Definition: precomp.h:100
VOID co_IntShellHookNotify(WPARAM Message, WPARAM wParam, LPARAM lParam)
Definition: desktop.c:1709
static PHOT_KEY FASTCALL IsHotKey(UINT fsModifiers, WORD wVk)
Definition: hotkey.c:165
UINT gfsModOnlyCandidate
Definition: hotkey.c:39
#define IsWindowHotKey(pHK)
Definition: hotkey.c:43
static UINT FASTCALL IntGetModifiers(PBYTE pKeyState)
Definition: hotkey.c:68
BYTE gafAsyncKeyState[256 *2/8]
Definition: keyboard.c:13
BOOL FASTCALL UserPostMessage(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1395
BOOL FASTCALL UserPostThreadMessage(PTHREADINFO pti, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: message.c:1358
LONG_PTR LPARAM
Definition: windef.h:208
#define WM_SYSCOMMAND
Definition: winuser.h:1760
#define VK_CONTROL
Definition: winuser.h:2222
#define SC_TASKLIST
Definition: winuser.h:2618
#define SC_HOTKEY
Definition: winuser.h:2620
#define VK_LWIN
Definition: winuser.h:2254
#define WM_HOTKEY
Definition: winuser.h:1898
#define VK_SHIFT
Definition: winuser.h:2221
#define WM_KEYDOWN
Definition: winuser.h:1734
#define VK_RWIN
Definition: winuser.h:2255
#define VK_MENU
Definition: winuser.h:2223

Referenced by ProcessKeyEvent().

◆ DefWndGetHotKey()

UINT FASTCALL DefWndGetHotKey ( PWND  pWnd)

Definition at line 338 of file hotkey.c.

339{
340 PHOT_KEY pHotKey = gphkFirst;
341
342 WARN("DefWndGetHotKey\n");
343
344 while (pHotKey)
345 {
346 if (pHotKey->pWnd == pWnd && IsWindowHotKey(pHotKey))
347 {
348 /* We have found it */
349 return MAKEWORD(pHotKey->vk, IntSwapModHKF(pHotKey->fsModifiers));
350 }
351
352 /* Move to the next entry */
353 pHotKey = pHotKey->pNext;
354 }
355
356 return 0;
357}
#define WARN(fmt,...)
Definition: precomp.h:61
UINT fsModifiers
Definition: hotkey.h:7
struct _HOT_KEY * pNext
Definition: hotkey.h:10
UINT vk
Definition: hotkey.h:8
#define MAKEWORD(a, b)
Definition: typedefs.h:248
PHOT_KEY gphkFirst
Definition: hotkey.c:38
static UCHAR IntSwapModHKF(UINT Input)
Definition: hotkey.c:94

Referenced by IntDefWindowProc().

◆ DefWndSetHotKey()

INT FASTCALL DefWndSetHotKey ( PWND  pWnd,
WPARAM  wParam 
)

Definition at line 365 of file hotkey.c.

366{
367 const UINT fsModifiers = IntSwapModHKF(HIBYTE(wParam));
368 const UINT vk = LOBYTE(wParam);
369 PHOT_KEY pHotKey, *pLink;
370 INT iRet = 1;
371
372 WARN("DefWndSetHotKey wParam 0x%x\n", wParam);
373
374 // A hot key cannot be associated with a child window.
375 if (pWnd->style & WS_CHILD)
376 return 0;
377
378 // VK_ESCAPE, VK_SPACE, VK_TAB and VK_PACKET are invalid hot keys.
379 if (vk == VK_ESCAPE || vk == VK_SPACE || vk == VK_TAB || vk == VK_PACKET)
380 {
381 return -1;
382 }
383
384 if (wParam)
385 {
386 pHotKey = gphkFirst;
387 while (pHotKey)
388 {
389 if (pHotKey->fsModifiers == fsModifiers &&
390 pHotKey->vk == vk &&
391 IsWindowHotKey(pHotKey))
392 {
393 if (pHotKey->pWnd != pWnd)
394 iRet = 2; // Another window already has the same hot key.
395 break;
396 }
397
398 /* Move to the next entry */
399 pHotKey = pHotKey->pNext;
400 }
401 }
402
403 pHotKey = gphkFirst;
404 pLink = &gphkFirst;
405 while (pHotKey)
406 {
407 if (pHotKey->pWnd == pWnd && IsWindowHotKey(pHotKey))
408 {
409 /* This window has already hotkey registered */
410 break;
411 }
412
413 /* Move to the next entry */
414 pLink = &pHotKey->pNext;
415 pHotKey = pHotKey->pNext;
416 }
417
418 if (wParam)
419 {
420 if (!pHotKey)
421 {
422 /* Create new hotkey */
424 if (pHotKey == NULL)
425 return 0;
426
427 pHotKey->pWnd = pWnd;
428 pHotKey->id = IDHK_WNDKEY; // Don't care, these hot keys are unrelated to the hot keys set by RegisterHotKey
429 pHotKey->pNext = gphkFirst;
430 gphkFirst = pHotKey;
431 }
432
433 /* A window can only have one hot key. If the window already has a
434 hot key associated with it, the new hot key replaces the old one. */
435 pHotKey->pti = NULL; /* IsWindowHotKey */
436 pHotKey->fsModifiers = fsModifiers;
437 pHotKey->vk = vk;
438 }
439 else if (pHotKey)
440 {
441 /* Remove hotkey */
442 *pLink = pHotKey->pNext;
444 }
445
446 return iRet;
447}
WPARAM wParam
Definition: combotst.c:138
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define IDHK_WNDKEY
Definition: hotkey.h:17
#define LOBYTE(W)
Definition: jmemdos.c:487
#define HIBYTE(W)
Definition: jmemdos.c:486
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
WORD vk
Definition: input.c:77
#define WS_CHILD
Definition: pedump.c:617
DWORD style
Definition: ntuser.h:706
int32_t INT
Definition: typedefs.h:58
#define USERTAG_HOTKEY
Definition: tags.h:238
#define VK_TAB
Definition: winuser.h:2218
#define VK_SPACE
Definition: winuser.h:2238
#define VK_ESCAPE
Definition: winuser.h:2233

Referenced by IntDefWindowProc().

◆ StartDebugHotKeys()

VOID FASTCALL StartDebugHotKeys ( VOID  )

Definition at line 46 of file hotkey.c.

47{
48 UINT vk = VK_F12;
52 {
54 }
57 TRACE("Start up the debugger hotkeys!! If you see this you enabled debugprints. Congrats!\n");
58}
#define MOD_SHIFT
Definition: imm.h:186
#define ENHANCED_KEYBOARD(Id)
Definition: ntddkbd.h:105
KEYBOARD_ID KeyboardIdentifier
Definition: ntddkbd.h:124
BOOL FASTCALL UserRegisterHotKey(PWND pWnd, int id, UINT fsModifiers, UINT vk)
Definition: hotkey.c:451
BOOL FASTCALL UserUnregisterHotKey(PWND pWnd, int id)
Definition: hotkey.c:499
KEYBOARD_ATTRIBUTES gKeyboardInfo
Definition: keyboard.c:17
#define VK_F12
Definition: winuser.h:2285
#define VK_SUBTRACT
Definition: winuser.h:2271

Referenced by RawInputThreadMain().

◆ UnregisterThreadHotKeys()

VOID FASTCALL UnregisterThreadHotKeys ( PTHREADINFO  pti)

Definition at line 135 of file hotkey.c.

136{
137 PHOT_KEY pHotKey = gphkFirst, phkNext, *pLink = &gphkFirst;
138
139 while (pHotKey)
140 {
141 /* Save next ptr for later use */
142 phkNext = pHotKey->pNext;
143
144 /* Should we delete this hotkey? */
145 if (pHotKey->pti == pti)
146 {
147 /* Update next ptr for previous hotkey and free memory */
148 *pLink = phkNext;
150 }
151 else /* This hotkey will stay, use its next ptr */
152 pLink = &pHotKey->pNext;
153
154 /* Move to the next entry */
155 pHotKey = phkNext;
156 }
157}

Referenced by ExitThreadCallback().

◆ UnregisterWindowHotKeys()

VOID FASTCALL UnregisterWindowHotKeys ( PWND  Window)

Definition at line 105 of file hotkey.c.

106{
107 PHOT_KEY pHotKey = gphkFirst, phkNext, *pLink = &gphkFirst;
108
109 while (pHotKey)
110 {
111 /* Save next ptr for later use */
112 phkNext = pHotKey->pNext;
113
114 /* Should we delete this hotkey? */
115 if (pHotKey->pWnd == pWnd)
116 {
117 /* Update next ptr for previous hotkey and free memory */
118 *pLink = phkNext;
120 }
121 else /* This hotkey will stay, use its next ptr */
122 pLink = &pHotKey->pNext;
123
124 /* Move to the next entry */
125 pHotKey = phkNext;
126 }
127}

Referenced by co_UserFreeWindow().

◆ UserRegisterHotKey()

BOOL FASTCALL UserRegisterHotKey ( PWND  pWnd,
int  id,
UINT  fsModifiers,
UINT  vk 
)

Definition at line 451 of file hotkey.c.

455{
456 PHOT_KEY pHotKey;
457 PTHREADINFO pHotKeyThread;
458
459 /* Find hotkey thread */
460 if (pWnd == NULL || pWnd == PWND_BOTTOM)
461 {
462 pHotKeyThread = PsGetCurrentThreadWin32Thread();
463 }
464 else
465 {
466 pHotKeyThread = pWnd->head.pti;
467 }
468
469 /* Check for existing hotkey */
470 if (IsHotKey(fsModifiers, vk))
471 {
473 WARN("Hotkey already exists\n");
474 return FALSE;
475 }
476
477 /* Create new hotkey */
479 if (pHotKey == NULL)
480 {
482 return FALSE;
483 }
484
485 pHotKey->pti = pHotKeyThread;
486 pHotKey->pWnd = pWnd;
487 pHotKey->fsModifiers = fsModifiers;
488 pHotKey->vk = vk;
489 pHotKey->id = id;
490
491 /* Insert hotkey to the global list */
492 pHotKey->pNext = gphkFirst;
493 gphkFirst = pHotKey;
494
495 return TRUE;
496}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
GLuint id
Definition: glext.h:5910
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
THRDESKHEAD head
Definition: ntuser.h:695
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:22
#define ERROR_HOTKEY_ALREADY_REGISTERED
Definition: winerror.h:890

Referenced by NtUserSetShellWindowEx(), RawInputThreadMain(), and StartDebugHotKeys().

◆ UserUnregisterHotKey()

BOOL FASTCALL UserUnregisterHotKey ( PWND  pWnd,
int  id 
)

Definition at line 499 of file hotkey.c.

500{
501 PHOT_KEY pHotKey = gphkFirst, phkNext, *pLink = &gphkFirst;
502 BOOL bRet = FALSE;
503
504 while (pHotKey)
505 {
506 /* Save next ptr for later use */
507 phkNext = pHotKey->pNext;
508
509 /* Should we delete this hotkey? */
510 if (pHotKey->pWnd == pWnd && pHotKey->id == id)
511 {
512 /* Update next ptr for previous hotkey and free memory */
513 *pLink = phkNext;
515
516 bRet = TRUE;
517 }
518 else /* This hotkey will stay, use its next ptr */
519 pLink = &pHotKey->pNext;
520
521 /* Move to the next entry */
522 pHotKey = phkNext;
523 }
524 return bRet;
525}

Referenced by StartDebugHotKeys().