2010-01-12 05:25:22 +00:00
|
|
|
/*
|
2003-11-02 16:33:51 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
2011-12-14 04:07:06 +00:00
|
|
|
* PROJECT: ReactOS Win32k subsystem
|
2003-11-02 16:33:51 +00:00
|
|
|
* PURPOSE: HotKey support
|
2013-10-14 06:19:48 +00:00
|
|
|
* FILE: win32ss/user/ntuser/hotkey.c
|
2003-11-02 16:33:51 +00:00
|
|
|
* PROGRAMER: Eric Kohl
|
|
|
|
*/
|
|
|
|
|
2005-09-18 23:06:15 +00:00
|
|
|
/*
|
2011-12-14 04:07:06 +00:00
|
|
|
* FIXME: Hotkey notifications are triggered by keyboard input (physical or programatically)
|
2013-04-13 21:28:10 +00:00
|
|
|
* and since only desktops on WinSta0 can receive input in seems very wrong to allow
|
|
|
|
* windows/threads on destops not belonging to WinSta0 to set hotkeys (receive notifications).
|
2011-12-14 04:07:06 +00:00
|
|
|
* -- Gunnar
|
|
|
|
*/
|
2005-09-18 23:06:15 +00:00
|
|
|
|
2010-04-26 13:58:46 +00:00
|
|
|
#include <win32k.h>
|
2011-08-21 12:38:52 +00:00
|
|
|
DBG_DEFAULT_CHANNEL(UserHotkey);
|
2003-11-02 16:33:51 +00:00
|
|
|
|
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
2013-06-18 23:51:14 +00:00
|
|
|
/*
|
|
|
|
* Hardcoded hotkeys. See http://ivanlef0u.fr/repo/windoz/VI20051005.html
|
|
|
|
* or http://repo.meh.or.id/Windows/VI20051005.html .
|
|
|
|
*
|
|
|
|
* NOTE: The (Shift-)F12 keys are used only for the "UserDebuggerHotKey" setting
|
|
|
|
* which enables setting a key shortcut which, when pressed, establishes a
|
|
|
|
* breakpoint in the code being debugged:
|
|
|
|
* see http://technet.microsoft.com/en-us/library/cc786263(v=ws.10).aspx
|
|
|
|
* and http://flylib.com/books/en/4.441.1.33/1/ for more details.
|
|
|
|
* By default the key is VK-F12 on a 101-key keyboard, and is VK_SUBTRACT
|
|
|
|
* (hyphen / substract sign) on a 82-key keyboard.
|
|
|
|
*/
|
2013-10-14 06:19:48 +00:00
|
|
|
/* pti pwnd modifiers vk id next */
|
|
|
|
// HOT_KEY hkF12 = {NULL, 1, 0, VK_F12, IDHK_F12, NULL};
|
|
|
|
// HOT_KEY hkShiftF12 = {NULL, 1, MOD_SHIFT, VK_F12, IDHK_SHIFTF12, &hkF12};
|
|
|
|
// HOT_KEY hkWinKey = {NULL, 1, MOD_WIN, 0, IDHK_WINKEY, &hkShiftF12};
|
2011-10-13 13:23:57 +00:00
|
|
|
|
2013-10-14 06:19:48 +00:00
|
|
|
PHOT_KEY gphkFirst = NULL;
|
2012-08-16 07:32:49 +00:00
|
|
|
BOOL bWinHotkeyActive = FALSE;
|
2005-09-18 23:06:15 +00:00
|
|
|
|
2003-11-02 16:33:51 +00:00
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2013-10-14 06:19:48 +00:00
|
|
|
VOID FASTCALL
|
|
|
|
StartDebugHotKeys(VOID)
|
|
|
|
{
|
|
|
|
UINT vk = VK_F12;
|
|
|
|
UserUnregisterHotKey(PWND_BOTTOM, IDHK_F12);
|
|
|
|
UserUnregisterHotKey(PWND_BOTTOM, IDHK_SHIFTF12);
|
|
|
|
if (!ENHANCED_KEYBOARD(gKeyboardInfo.KeyboardIdentifier))
|
|
|
|
{
|
|
|
|
vk = VK_SUBTRACT;
|
|
|
|
}
|
|
|
|
UserRegisterHotKey(PWND_BOTTOM, IDHK_SHIFTF12, MOD_SHIFT, vk);
|
|
|
|
UserRegisterHotKey(PWND_BOTTOM, IDHK_F12, 0, vk);
|
|
|
|
ERR("Start up the debugger hotkeys!! Should see this once!\n");
|
|
|
|
}
|
|
|
|
|
2011-10-09 20:12:12 +00:00
|
|
|
/*
|
|
|
|
* IntGetModifiers
|
|
|
|
*
|
|
|
|
* Returns a value that indicates if the key is a modifier key, and
|
|
|
|
* which one.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
UINT FASTCALL
|
|
|
|
IntGetModifiers(PBYTE pKeyState)
|
2003-11-03 18:52:21 +00:00
|
|
|
{
|
2011-10-09 20:12:12 +00:00
|
|
|
UINT fModifiers = 0;
|
2011-10-09 20:41:09 +00:00
|
|
|
|
2011-10-09 20:12:12 +00:00
|
|
|
if (IS_KEY_DOWN(pKeyState, VK_SHIFT))
|
|
|
|
fModifiers |= MOD_SHIFT;
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2011-10-09 20:12:12 +00:00
|
|
|
if (IS_KEY_DOWN(pKeyState, VK_CONTROL))
|
|
|
|
fModifiers |= MOD_CONTROL;
|
2003-11-03 18:52:21 +00:00
|
|
|
|
2011-10-09 20:12:12 +00:00
|
|
|
if (IS_KEY_DOWN(pKeyState, VK_MENU))
|
|
|
|
fModifiers |= MOD_ALT;
|
2003-11-03 18:52:21 +00:00
|
|
|
|
2011-10-09 20:12:12 +00:00
|
|
|
if (IS_KEY_DOWN(pKeyState, VK_LWIN) || IS_KEY_DOWN(pKeyState, VK_RWIN))
|
|
|
|
fModifiers |= MOD_WIN;
|
2003-11-03 18:52:21 +00:00
|
|
|
|
2011-10-09 20:12:12 +00:00
|
|
|
return fModifiers;
|
2003-11-03 18:52:21 +00:00
|
|
|
}
|
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/*
|
|
|
|
* UnregisterWindowHotKeys
|
|
|
|
*
|
|
|
|
* Removes hotkeys registered by specified window on its cleanup
|
|
|
|
*/
|
2005-09-18 23:06:15 +00:00
|
|
|
VOID FASTCALL
|
2011-10-13 13:23:57 +00:00
|
|
|
UnregisterWindowHotKeys(PWND pWnd)
|
2003-11-03 18:52:21 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
PHOT_KEY pHotKey = gphkFirst, phkNext, *pLink = &gphkFirst;
|
2011-10-09 20:41:09 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
while (pHotKey)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Save next ptr for later use */
|
|
|
|
phkNext = pHotKey->pNext;
|
|
|
|
|
|
|
|
/* Should we delete this hotkey? */
|
2013-10-14 06:19:48 +00:00
|
|
|
if (pHotKey->pWnd == pWnd)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Update next ptr for previous hotkey and free memory */
|
|
|
|
*pLink = phkNext;
|
|
|
|
ExFreePoolWithTag(pHotKey, USERTAG_HOTKEY);
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
2011-10-13 13:23:57 +00:00
|
|
|
else /* This hotkey will stay, use its next ptr */
|
|
|
|
pLink = &pHotKey->pNext;
|
|
|
|
|
|
|
|
/* Move to the next entry */
|
|
|
|
pHotKey = phkNext;
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
2003-11-03 18:52:21 +00:00
|
|
|
}
|
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/*
|
|
|
|
* UnregisterThreadHotKeys
|
|
|
|
*
|
|
|
|
* Removes hotkeys registered by specified thread on its cleanup
|
|
|
|
*/
|
2005-09-18 23:06:15 +00:00
|
|
|
VOID FASTCALL
|
2013-10-14 06:19:48 +00:00
|
|
|
UnregisterThreadHotKeys(PTHREADINFO pti)
|
2003-11-03 18:52:21 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
PHOT_KEY pHotKey = gphkFirst, phkNext, *pLink = &gphkFirst;
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
while (pHotKey)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Save next ptr for later use */
|
|
|
|
phkNext = pHotKey->pNext;
|
|
|
|
|
|
|
|
/* Should we delete this hotkey? */
|
2013-10-14 06:19:48 +00:00
|
|
|
if (pHotKey->pti == pti)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Update next ptr for previous hotkey and free memory */
|
|
|
|
*pLink = phkNext;
|
|
|
|
ExFreePoolWithTag(pHotKey, USERTAG_HOTKEY);
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
2011-10-13 13:23:57 +00:00
|
|
|
else /* This hotkey will stay, use its next ptr */
|
|
|
|
pLink = &pHotKey->pNext;
|
2003-11-03 18:52:21 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Move to the next entry */
|
|
|
|
pHotKey = phkNext;
|
|
|
|
}
|
2003-11-03 18:52:21 +00:00
|
|
|
}
|
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/*
|
|
|
|
* IsHotKey
|
|
|
|
*
|
|
|
|
* Checks if given key and modificators have corresponding hotkey
|
|
|
|
*/
|
|
|
|
static PHOT_KEY FASTCALL
|
2011-10-09 20:12:12 +00:00
|
|
|
IsHotKey(UINT fsModifiers, WORD wVk)
|
2003-11-03 18:52:21 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
PHOT_KEY pHotKey = gphkFirst;
|
2003-11-03 18:52:21 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
while (pHotKey)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
if (pHotKey->fsModifiers == fsModifiers &&
|
|
|
|
pHotKey->vk == wVk)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
/* We have found it */
|
|
|
|
return pHotKey;
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
2011-10-13 13:23:57 +00:00
|
|
|
|
|
|
|
/* Move to the next entry */
|
|
|
|
pHotKey = pHotKey->pNext;
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
2003-11-03 18:52:21 +00:00
|
|
|
|
2011-10-09 20:41:09 +00:00
|
|
|
return NULL;
|
2011-10-09 20:12:12 +00:00
|
|
|
}
|
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/*
|
|
|
|
* co_UserProcessHotKeys
|
|
|
|
*
|
|
|
|
* Sends WM_HOTKEY message if given keys are hotkey
|
|
|
|
*/
|
2011-10-09 20:12:12 +00:00
|
|
|
BOOL NTAPI
|
2011-10-09 20:27:08 +00:00
|
|
|
co_UserProcessHotKeys(WORD wVk, BOOL bIsDown)
|
2011-10-09 20:12:12 +00:00
|
|
|
{
|
|
|
|
UINT fModifiers;
|
2011-10-13 13:23:57 +00:00
|
|
|
PHOT_KEY pHotKey;
|
2013-10-14 06:19:48 +00:00
|
|
|
PWND pWnd;
|
|
|
|
BOOL DoNotPostMsg = FALSE;
|
2011-10-13 13:23:57 +00:00
|
|
|
|
|
|
|
if (wVk == VK_SHIFT || wVk == VK_CONTROL || wVk == VK_MENU ||
|
|
|
|
wVk == VK_LWIN || wVk == VK_RWIN)
|
|
|
|
{
|
|
|
|
/* Those keys are specified by modifiers */
|
|
|
|
wVk = 0;
|
|
|
|
}
|
2011-10-09 20:12:12 +00:00
|
|
|
|
|
|
|
fModifiers = IntGetModifiers(gafAsyncKeyState);
|
2013-10-14 06:19:48 +00:00
|
|
|
|
|
|
|
/* Check if it is a hotkey */
|
2011-10-09 20:12:12 +00:00
|
|
|
pHotKey = IsHotKey(fModifiers, wVk);
|
2013-10-14 06:19:48 +00:00
|
|
|
|
2011-10-09 20:12:12 +00:00
|
|
|
if (pHotKey)
|
|
|
|
{
|
2013-10-15 07:05:17 +00:00
|
|
|
TRACE("Hot key pressed (pWnd %p, id %d)\n", pHotKey->pWnd, pHotKey->id);
|
|
|
|
|
2013-10-14 06:19:48 +00:00
|
|
|
/* FIXME: See comment about "UserDebuggerHotKey" on top of this file. */
|
|
|
|
if (pHotKey->id == IDHK_SHIFTF12 || pHotKey->id == IDHK_F12)
|
|
|
|
{
|
|
|
|
if (bIsDown)
|
|
|
|
{
|
|
|
|
ERR("Hot key pressed for Debug Activation! ShiftF12 = %d or F12 = %d\n",pHotKey->id == IDHK_SHIFTF12 , pHotKey->id == IDHK_F12);
|
|
|
|
//DoNotPostMsg = co_ActivateDebugger(); // FIXME
|
|
|
|
}
|
|
|
|
return DoNotPostMsg;
|
|
|
|
}
|
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Process hotkey if it is key up event */
|
|
|
|
if (!bIsDown)
|
2011-10-09 20:12:12 +00:00
|
|
|
{
|
2013-10-14 06:19:48 +00:00
|
|
|
/* WIN and F12 keys are not hardcoded here. See comments on top of this file. */
|
|
|
|
if (pHotKey->id == IDHK_WINKEY && bWinHotkeyActive == TRUE)
|
2012-08-16 07:32:49 +00:00
|
|
|
{
|
2013-10-14 06:19:48 +00:00
|
|
|
pWnd = ValidateHwndNoErr(InputWindowStation->ShellWindow);
|
|
|
|
if (pWnd)
|
2012-08-16 07:32:49 +00:00
|
|
|
{
|
2013-10-14 06:19:48 +00:00
|
|
|
TRACE("System Hot key Id %d Key %d\n",pHotKey->id, wVk );
|
|
|
|
UserPostMessage(UserHMGetHandle(pWnd), WM_SYSCOMMAND, SC_TASKLIST, 0);
|
|
|
|
//ptiLastInput = pWnd->head.pti;
|
|
|
|
bWinHotkeyActive = FALSE;
|
2013-10-15 07:05:17 +00:00
|
|
|
return FALSE;
|
2012-08-16 07:32:49 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-15 07:05:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* The user pressed the win key */
|
|
|
|
if (pHotKey->id == IDHK_WINKEY)
|
|
|
|
{
|
|
|
|
bWinHotkeyActive = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2013-10-14 06:19:48 +00:00
|
|
|
|
2013-10-15 07:05:17 +00:00
|
|
|
if (bIsDown)
|
|
|
|
{
|
2013-10-14 06:19:48 +00:00
|
|
|
if (!pHotKey->pWnd)
|
2011-10-13 13:23:57 +00:00
|
|
|
{
|
2013-10-14 06:19:48 +00:00
|
|
|
TRACE("UPTM Hot key Id %d Key %d\n",pHotKey->id, wVk );
|
|
|
|
UserPostThreadMessage(pHotKey->pti, WM_HOTKEY, pHotKey->id, MAKELONG(fModifiers, wVk));
|
|
|
|
//ptiLastInput = pHotKey->pti;
|
2013-10-15 07:05:17 +00:00
|
|
|
return TRUE; /* Don't send any message */
|
2011-10-13 13:23:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-14 06:19:48 +00:00
|
|
|
if (pHotKey->pWnd == PWND_BOTTOM)
|
|
|
|
{
|
|
|
|
if (gpqForeground != NULL)
|
|
|
|
{
|
|
|
|
pWnd = gpqForeground->spwndFocus;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pWnd = pHotKey->pWnd;
|
|
|
|
}
|
|
|
|
if (pWnd)
|
2013-10-15 07:05:17 +00:00
|
|
|
{ // pWnd->head.rpdesk->pDeskInfo->spwndShell needs testing.
|
|
|
|
if (pWnd == ValidateHwndNoErr(InputWindowStation->ShellWindow) && pHotKey->id == SC_TASKLIST)
|
2013-10-14 06:19:48 +00:00
|
|
|
{
|
|
|
|
ERR("Sending to shell window w/o IDHK_WINKEY..\n");
|
|
|
|
UserPostMessage(UserHMGetHandle(pWnd), WM_SYSCOMMAND, SC_TASKLIST, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-15 07:05:17 +00:00
|
|
|
TRACE("UPM Hot key Id %d Key %d\n",pHotKey->id, wVk );
|
2013-10-14 06:19:48 +00:00
|
|
|
UserPostMessage(UserHMGetHandle(pWnd), WM_HOTKEY, pHotKey->id, MAKELONG(fModifiers, wVk));
|
|
|
|
}
|
|
|
|
//ptiLastInput = pWnd->head.pti;
|
2013-10-15 07:05:17 +00:00
|
|
|
return TRUE; /* Don't send any message */
|
2013-10-14 06:19:48 +00:00
|
|
|
}
|
2012-08-16 07:32:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-09 20:12:12 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
2003-11-03 18:52:21 +00:00
|
|
|
}
|
|
|
|
|
2011-10-09 20:12:12 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/*
|
|
|
|
* DefWndGetHotKey
|
|
|
|
*
|
|
|
|
* GetHotKey message support
|
|
|
|
*/
|
2011-04-25 15:18:39 +00:00
|
|
|
UINT FASTCALL
|
2013-10-14 06:19:48 +00:00
|
|
|
DefWndGetHotKey(PWND pWnd)
|
2011-04-25 15:18:39 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
PHOT_KEY pHotKey = gphkFirst;
|
2011-04-25 15:18:39 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
WARN("DefWndGetHotKey\n");
|
2011-04-25 15:18:39 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
while (pHotKey)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2013-10-14 06:19:48 +00:00
|
|
|
if (pHotKey->pWnd == pWnd && pHotKey->id == IDHK_REACTOS)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
/* We have found it */
|
|
|
|
return MAKELONG(pHotKey->vk, pHotKey->fsModifiers);
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
2011-10-13 13:23:57 +00:00
|
|
|
|
|
|
|
/* Move to the next entry */
|
|
|
|
pHotKey = pHotKey->pNext;
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
2011-10-13 13:23:57 +00:00
|
|
|
|
2011-10-09 20:41:09 +00:00
|
|
|
return 0;
|
2011-04-25 15:18:39 +00:00
|
|
|
}
|
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/*
|
|
|
|
* DefWndSetHotKey
|
|
|
|
*
|
|
|
|
* SetHotKey message support
|
|
|
|
*/
|
2011-10-09 20:41:09 +00:00
|
|
|
INT FASTCALL
|
|
|
|
DefWndSetHotKey(PWND pWnd, WPARAM wParam)
|
2011-04-25 15:18:39 +00:00
|
|
|
{
|
2011-10-09 20:41:09 +00:00
|
|
|
UINT fsModifiers, vk;
|
2011-10-13 13:23:57 +00:00
|
|
|
PHOT_KEY pHotKey, *pLink;
|
|
|
|
INT iRet = 1;
|
2011-04-25 15:18:39 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
WARN("DefWndSetHotKey wParam 0x%x\n", wParam);
|
2011-04-25 15:18:39 +00:00
|
|
|
|
2011-10-09 20:41:09 +00:00
|
|
|
// A hot key cannot be associated with a child window.
|
2011-10-13 13:23:57 +00:00
|
|
|
if (pWnd->style & WS_CHILD)
|
|
|
|
return 0;
|
2011-04-25 15:18:39 +00:00
|
|
|
|
2011-10-09 20:41:09 +00:00
|
|
|
// VK_ESCAPE, VK_SPACE, and VK_TAB are invalid hot keys.
|
|
|
|
if (LOWORD(wParam) == VK_ESCAPE ||
|
2011-04-25 15:18:39 +00:00
|
|
|
LOWORD(wParam) == VK_SPACE ||
|
2011-10-13 13:23:57 +00:00
|
|
|
LOWORD(wParam) == VK_TAB)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2011-10-09 20:41:09 +00:00
|
|
|
|
|
|
|
vk = LOWORD(wParam);
|
|
|
|
fsModifiers = HIWORD(wParam);
|
|
|
|
|
|
|
|
if (wParam)
|
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
pHotKey = gphkFirst;
|
|
|
|
while (pHotKey)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
if (pHotKey->fsModifiers == fsModifiers &&
|
|
|
|
pHotKey->vk == vk &&
|
|
|
|
pHotKey->id == IDHK_REACTOS)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2013-10-14 06:19:48 +00:00
|
|
|
if (pHotKey->pWnd != pWnd)
|
2011-10-13 13:23:57 +00:00
|
|
|
iRet = 2; // Another window already has the same hot key.
|
2011-10-09 20:41:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-10-13 13:23:57 +00:00
|
|
|
|
|
|
|
/* Move to the next entry */
|
|
|
|
pHotKey = pHotKey->pNext;
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-13 13:23:57 +00:00
|
|
|
|
|
|
|
pHotKey = gphkFirst;
|
|
|
|
pLink = &gphkFirst;
|
|
|
|
while (pHotKey)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2013-10-14 06:19:48 +00:00
|
|
|
if (pHotKey->pWnd == pWnd &&
|
2011-10-13 13:23:57 +00:00
|
|
|
pHotKey->id == IDHK_REACTOS)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
/* This window has already hotkey registered */
|
2011-04-25 15:18:39 +00:00
|
|
|
break;
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Move to the next entry */
|
|
|
|
pLink = &pHotKey->pNext;
|
|
|
|
pHotKey = pHotKey->pNext;
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
if (wParam)
|
|
|
|
{
|
|
|
|
if (!pHotKey)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Create new hotkey */
|
|
|
|
pHotKey = ExAllocatePoolWithTag(PagedPool, sizeof(HOT_KEY), USERTAG_HOTKEY);
|
|
|
|
if (pHotKey == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2013-10-14 06:19:48 +00:00
|
|
|
pHotKey->pWnd = pWnd;
|
2011-10-13 13:23:57 +00:00
|
|
|
pHotKey->id = IDHK_REACTOS; // Don't care, these hot keys are unrelated to the hot keys set by RegisterHotKey
|
|
|
|
pHotKey->pNext = gphkFirst;
|
|
|
|
gphkFirst = pHotKey;
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/* A window can only have one hot key. If the window already has a
|
|
|
|
hot key associated with it, the new hot key replaces the old one. */
|
2013-10-14 06:19:48 +00:00
|
|
|
pHotKey->pti = NULL;
|
2011-10-13 13:23:57 +00:00
|
|
|
pHotKey->fsModifiers = fsModifiers;
|
|
|
|
pHotKey->vk = vk;
|
|
|
|
}
|
|
|
|
else if (pHotKey)
|
|
|
|
{
|
|
|
|
/* Remove hotkey */
|
|
|
|
*pLink = pHotKey->pNext;
|
|
|
|
ExFreePoolWithTag(pHotKey, USERTAG_HOTKEY);
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
2011-10-13 13:23:57 +00:00
|
|
|
|
|
|
|
return iRet;
|
2011-04-25 15:18:39 +00:00
|
|
|
}
|
2005-09-19 00:02:39 +00:00
|
|
|
|
2013-10-14 06:19:48 +00:00
|
|
|
|
|
|
|
BOOL FASTCALL
|
|
|
|
UserRegisterHotKey(PWND pWnd,
|
|
|
|
int id,
|
|
|
|
UINT fsModifiers,
|
|
|
|
UINT vk)
|
|
|
|
{
|
|
|
|
PHOT_KEY pHotKey;
|
|
|
|
PTHREADINFO pHotKeyThread;
|
|
|
|
|
|
|
|
/* Find hotkey thread */
|
|
|
|
if (pWnd == NULL || pWnd == PWND_BOTTOM)
|
|
|
|
{
|
|
|
|
pHotKeyThread = PsGetCurrentThreadWin32Thread();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pHotKeyThread = pWnd->head.pti;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for existing hotkey */
|
|
|
|
if (IsHotKey(fsModifiers, vk))
|
|
|
|
{
|
|
|
|
EngSetLastError(ERROR_HOTKEY_ALREADY_REGISTERED);
|
|
|
|
WARN("Hotkey already exists\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create new hotkey */
|
|
|
|
pHotKey = ExAllocatePoolWithTag(PagedPool, sizeof(HOT_KEY), USERTAG_HOTKEY);
|
|
|
|
if (pHotKey == NULL)
|
|
|
|
{
|
|
|
|
EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pHotKey->pti = pHotKeyThread;
|
|
|
|
pHotKey->pWnd = pWnd;
|
|
|
|
pHotKey->fsModifiers = fsModifiers;
|
|
|
|
pHotKey->vk = vk;
|
|
|
|
pHotKey->id = id;
|
|
|
|
|
|
|
|
/* Insert hotkey to the global list */
|
|
|
|
pHotKey->pNext = gphkFirst;
|
|
|
|
gphkFirst = pHotKey;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL FASTCALL
|
|
|
|
UserUnregisterHotKey(PWND pWnd, int id)
|
|
|
|
{
|
|
|
|
PHOT_KEY pHotKey = gphkFirst, phkNext, *pLink = &gphkFirst;
|
|
|
|
BOOL bRet = FALSE;
|
|
|
|
|
|
|
|
while (pHotKey)
|
|
|
|
{
|
|
|
|
/* Save next ptr for later use */
|
|
|
|
phkNext = pHotKey->pNext;
|
|
|
|
|
|
|
|
/* Should we delete this hotkey? */
|
|
|
|
if (pHotKey->pWnd == pWnd && pHotKey->id == id)
|
|
|
|
{
|
|
|
|
/* Update next ptr for previous hotkey and free memory */
|
|
|
|
*pLink = phkNext;
|
|
|
|
ExFreePoolWithTag(pHotKey, USERTAG_HOTKEY);
|
|
|
|
|
|
|
|
bRet = TRUE;
|
|
|
|
}
|
|
|
|
else /* This hotkey will stay, use its next ptr */
|
|
|
|
pLink = &pHotKey->pNext;
|
|
|
|
|
|
|
|
/* Move to the next entry */
|
|
|
|
pHotKey = phkNext;
|
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-19 00:02:39 +00:00
|
|
|
/* SYSCALLS *****************************************************************/
|
|
|
|
|
|
|
|
|
2008-11-29 22:48:58 +00:00
|
|
|
BOOL APIENTRY
|
2003-11-02 16:33:51 +00:00
|
|
|
NtUserRegisterHotKey(HWND hWnd,
|
2005-09-07 21:25:42 +00:00
|
|
|
int id,
|
|
|
|
UINT fsModifiers,
|
|
|
|
UINT vk)
|
2003-11-02 16:33:51 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
PHOT_KEY pHotKey;
|
2013-10-14 06:19:48 +00:00
|
|
|
PWND pWnd = NULL;
|
|
|
|
PTHREADINFO pHotKeyThread;
|
2011-10-13 13:23:57 +00:00
|
|
|
BOOL bRet = FALSE;
|
2011-10-09 20:41:09 +00:00
|
|
|
|
|
|
|
TRACE("Enter NtUserRegisterHotKey\n");
|
2011-10-13 13:23:57 +00:00
|
|
|
|
2011-12-14 04:07:06 +00:00
|
|
|
if (fsModifiers & ~(MOD_ALT|MOD_CONTROL|MOD_SHIFT|MOD_WIN)) // FIXME: Does Win2k3 support MOD_NOREPEAT?
|
2011-10-13 13:23:57 +00:00
|
|
|
{
|
|
|
|
WARN("Invalid modifiers: %x\n", fsModifiers);
|
|
|
|
EngSetLastError(ERROR_INVALID_FLAGS);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-09 20:41:09 +00:00
|
|
|
UserEnterExclusive();
|
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Find hotkey thread */
|
2011-10-09 20:41:09 +00:00
|
|
|
if (hWnd == NULL)
|
|
|
|
{
|
2013-10-14 06:19:48 +00:00
|
|
|
pHotKeyThread = gptiCurrent;
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
pWnd = UserGetWindowObject(hWnd);
|
|
|
|
if (!pWnd)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-10-14 06:19:48 +00:00
|
|
|
pHotKeyThread = pWnd->head.pti;
|
|
|
|
|
|
|
|
/* Fix wine msg "Window on another thread" test_hotkey */
|
|
|
|
if (pWnd->head.pti != gptiCurrent)
|
|
|
|
{
|
2013-10-14 21:51:07 +00:00
|
|
|
EngSetLastError(ERROR_WINDOW_OF_OTHER_THREAD);
|
2013-10-14 06:19:48 +00:00
|
|
|
WARN("Must be from the same Thread.\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for existing hotkey */
|
|
|
|
if (IsHotKey(fsModifiers, vk))
|
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
EngSetLastError(ERROR_HOTKEY_ALREADY_REGISTERED);
|
|
|
|
WARN("Hotkey already exists\n");
|
|
|
|
goto cleanup;
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Create new hotkey */
|
|
|
|
pHotKey = ExAllocatePoolWithTag(PagedPool, sizeof(HOT_KEY), USERTAG_HOTKEY);
|
|
|
|
if (pHotKey == NULL)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
goto cleanup;
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 06:19:48 +00:00
|
|
|
pHotKey->pti = pHotKeyThread;
|
|
|
|
pHotKey->pWnd = pWnd;
|
2011-10-13 13:23:57 +00:00
|
|
|
pHotKey->fsModifiers = fsModifiers;
|
|
|
|
pHotKey->vk = vk;
|
|
|
|
pHotKey->id = id;
|
2011-10-09 20:41:09 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Insert hotkey to the global list */
|
|
|
|
pHotKey->pNext = gphkFirst;
|
|
|
|
gphkFirst = pHotKey;
|
2011-10-09 20:41:09 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
bRet = TRUE;
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
cleanup:
|
|
|
|
TRACE("Leave NtUserRegisterHotKey, ret=%i\n", bRet);
|
2011-10-09 20:41:09 +00:00
|
|
|
UserLeave();
|
2011-10-13 13:23:57 +00:00
|
|
|
return bRet;
|
2003-11-02 16:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-29 22:48:58 +00:00
|
|
|
BOOL APIENTRY
|
2005-09-18 23:06:15 +00:00
|
|
|
NtUserUnregisterHotKey(HWND hWnd, int id)
|
2003-11-02 16:33:51 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
PHOT_KEY pHotKey = gphkFirst, phkNext, *pLink = &gphkFirst;
|
|
|
|
BOOL bRet = FALSE;
|
2013-10-15 07:05:17 +00:00
|
|
|
PWND pWnd = NULL;
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2011-10-09 20:41:09 +00:00
|
|
|
TRACE("Enter NtUserUnregisterHotKey\n");
|
|
|
|
UserEnterExclusive();
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2011-10-21 14:54:22 +00:00
|
|
|
/* Fail if given window is invalid */
|
2013-10-14 06:19:48 +00:00
|
|
|
if (hWnd && !(pWnd = UserGetWindowObject(hWnd)))
|
2011-10-13 13:23:57 +00:00
|
|
|
goto cleanup;
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
while (pHotKey)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Save next ptr for later use */
|
|
|
|
phkNext = pHotKey->pNext;
|
|
|
|
|
|
|
|
/* Should we delete this hotkey? */
|
2013-10-14 06:19:48 +00:00
|
|
|
if (pHotKey->pWnd == pWnd && pHotKey->id == id)
|
2011-10-09 20:41:09 +00:00
|
|
|
{
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Update next ptr for previous hotkey and free memory */
|
|
|
|
*pLink = phkNext;
|
|
|
|
ExFreePoolWithTag(pHotKey, USERTAG_HOTKEY);
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
bRet = TRUE;
|
2011-10-09 20:41:09 +00:00
|
|
|
}
|
2011-10-13 13:23:57 +00:00
|
|
|
else /* This hotkey will stay, use its next ptr */
|
|
|
|
pLink = &pHotKey->pNext;
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
/* Move to the next entry */
|
|
|
|
pHotKey = phkNext;
|
|
|
|
}
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2011-10-13 13:23:57 +00:00
|
|
|
cleanup:
|
|
|
|
TRACE("Leave NtUserUnregisterHotKey, ret=%i\n", bRet);
|
2011-10-09 20:41:09 +00:00
|
|
|
UserLeave();
|
2011-10-13 13:23:57 +00:00
|
|
|
return bRet;
|
2003-11-02 16:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|