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 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 120
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.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