Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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.
 
 
int WinS;
int WinA;
 
RegisterHotKey(hWnd,WinS, MOD_WIN, 'S');
// RegisterHotKey(hWnd,WinA, MOD_WIN, 'A');

 
Window message loop
 
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-Apr-13 18:52pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
RegisterHotKey(hWnd, 1, MOD_WIN, 'S');
RegisterHotKey(hWnd, 2, MOD_WIN, 'A');
  Permalink  
Comments
Ron Anders at 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)

  Print Answers RSS
0 Marcin Kozub 330
1 OriginalGriff 256
2 Sergey Alexandrovich Kryukov 215
3 Praneet Nadkar 197
4 Richard MacCutchan 182
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100