Processing Alt + Enter

Started by
2 comments, last by ProjectinMatrix 12 years, 6 months ago
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);
}
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?



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.
Thanks KaRei, that solved it!



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

This topic is closed to new replies.

Advertisement