Does the shortcut key registered by the RegisterHotKey API still exist after the process exits? Will it automatically log out?

勇强 韩 136 Reputation points
2023-08-10T08:00:19.3333333+00:00

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;
    }
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,756 questions
{count} votes

Accepted answer
  1. Castorix31 88,381 Reputation points
    2023-08-10T08:46:52.7066667+00:00

    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

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.