Click here to Skip to main content
Rate this: bad
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)
		if(msg.lParam == 0x00530008)
Posted 1-Apr-13 18:52pm

1 solution

Rate this: bad
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');
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 Maciej Los 495
1 Sergey Alexandrovich Kryukov 419
2 OriginalGriff 360
3 CHill60 310
4 CPallini 275
0 Sergey Alexandrovich Kryukov 10,017
1 OriginalGriff 9,495
2 Peter Leow 5,241
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,076

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2015
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