• Advertisement
Sign in to follow this  

Processing Alt + Enter

This topic is 2327 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys, i'm trying to process alt + enter in the windows message loop. After some research i found that when receiving a WM_KEYDOWN message the lparam contains a bit that should be set when the alt key is down. I have this implemented in my message loop (pasted below), however it does not work as expected. Alt+Enter does nothing, but Ctrl + Alt + Enter causes the ToggleFullScreen function to execute. Any idea why this may be happening? A quick solution perhaps?



LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
switch (iMsg) {
case WM_CREATE :
break;
case WM_CLOSE :
DestroyWindow(hwnd);
break;
case WM_DESTROY :
PostQuitMessage(0);
break;
case WM_KEYDOWN:
if (wParam == VK_RETURN)
if ((HIWORD(lParam) & KF_ALTDOWN))
ToggleFullscreen();
break;
case WM_SIZE:
OpenGLResetProjection();
break;
case WM_ACTIVATE:
if (LOWORD(wParam) != WA_INACTIVE)
Suspend(false);
else
Suspend(true);
break;
case WM_SYSKEYUP:
case WM_SYSCHAR:
case WM_PAINT:
case WM_ERASEBKGND:
return 0;
}

return DefWindowProc(hwnd, iMsg, wParam, lParam);
}

Share this post


Link to post
Share on other sites
Advertisement
Are you using different Alt's for each key press? Are using the left side alt when you click ctrl + alt + enter versus the right side alt when pressing alt + enter?

Share this post


Link to post
Share on other sites
The problem is you won't receive WM_KEYDOWN message when you hold (left) ALT, but WM_SYSKEYDOWN message instead.
Alt + some_key is recognized as a system command combination, therefore sends a SYS- message.
Ctrl + Alt + some_key isn't a system command combination, therefore sends a nonSYS- message.

WM_KEYDOWN

WM_SYSKEYDOWN

Note:
Only the left Alt works in this way, i.e. WM_SYSKEYDOWN.
With the right Alt you'll receive the ordinary WM_KEYDOWN message.

Share this post


Link to post
Share on other sites
Thanks KaRei, that solved it!



case WM_KEYDOWN:
case WM_SYSKEYDOWN:
if (wParam == VK_RETURN)
if ((HIWORD(lParam) & KF_ALTDOWN))
ToggleFullscreen();
break;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement