Click here to Skip to main content
13,139,569 members (50,029 online)
Rate this:
Please Sign up or sign in to 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.

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 17: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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2017
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