Click here to Skip to main content
15,884,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Why oh why.

I have a message only window that I have assigned a hotkey Win + S to.
This has worked well.

I wished to add a Win + A hot key so I thought I could just register another one.

The following code works with Win+S but if I uncomment the Win+A Registerhotkey then
msg.message == WM_HOTKEY is never true when Win+S is pressed but is true if Win+A is pressed.

As if I cannot have two hotkeys assigned to this message window? Bah. - Can't be.

C++
int WinS;
int WinA;

RegisterHotKey(hWnd,WinS, MOD_WIN, 'S');
// RegisterHotKey(hWnd,WinA, MOD_WIN, 'A');


Window message loop

C++
void message_loop()
{

        MSG msg = {0};

        while (GetMessage(&msg, NULL, 0, 0))
        {
	    if(msg.message == WM_HOTKEY)
	    {
		if(msg.lParam == 0x00410008)
		{
	        	AfxMessageBox("Win+A");
		}
		if(msg.lParam == 0x00530008)
		{
		        AfxMessageBox("Win+S");
		}
            }
            TranslateMessage(&msg);
            DispatchMessage(&msg);
       }
}
Posted

1 solution

See the RegisterHotkey()[^] function in the MSDN and read the remarks. The second id parameter must be different for each defined key. You are passing uninitialized values which are probably set to zero by the compiler resulting in identical IDs.
To resolve this, pass different IDs:
C++
RegisterHotKey(hWnd, 1, MOD_WIN, 'S');
RegisterHotKey(hWnd, 2, MOD_WIN, 'A');
 
Share this answer
 
Comments
Ron Anders 2-Apr-13 9:39am    
I should be taken out back and shot.

Thank you for helping me see this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900