Does the shortcut key registered by the RegisterHotKey API still exist after the process exits?
No.
The OS frees all resources of a process when it is terminated
Hotkeys are stored in a Hash table in Kernel, with hWnd and Thread ID
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
RT
My program registered a shortcut key using the RegisterHotKey API, but did not execute UnRegisterHotKey when the program exited. May I ask if registering the same shortcut key again when starting the program would conflict? What I am actually testing here is that it will not conflict? What is the reason for this?
UINT RegisterHotkey(HotKey hkHotkey, IHotkeyReceiver* pHotkeyReceiver, UINT uHotkeyID = (UINT)-1)
{
if(uHotkeyID==(UINT)-1)
{
uHotkeyID = m_nCurrentHotkeyID++;
}
T* pThis = static_cast<T*>(this);
UINT fsModifiers = 0;
UINT hkModifiers = hkHotkey>>8;
if(hkModifiers & HOTKEYF_ALT)
{
fsModifiers |= MOD_ALT;
}
if(hkModifiers & HOTKEYF_CONTROL)
{
fsModifiers |= MOD_CONTROL;
}
if(hkModifiers & HOTKEYF_SHIFT)
{
fsModifiers |= MOD_SHIFT;
}
if(!RegisterHotKey(pThis->m_hWnd, uHotkeyID, fsModifiers, hkHotkey & 0x00FF))
{
return (UINT)-1;
}
m_pHotkeyMap.SetAt(uHotkeyID, pHotkeyReceiver);
return uHotkeyID;
}
Does the shortcut key registered by the RegisterHotKey API still exist after the process exits?
No.
The OS frees all resources of a process when it is terminated
Hotkeys are stored in a Hash table in Kernel, with hWnd and Thread ID