Sign in to follow this  
ProjectinMatrix

Processing Alt + Enter

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?


[code]
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);
}[/code]

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 [b]WM_SYSKEYDOWN[/b] message instead.
[b]Alt + some_key[/b] is recognized as a system command combination, therefore sends a SYS- message.
[b]Ctrl + Alt + some_key[/b] isn't a system command combination, therefore sends a nonSYS- message.

[url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms646280%28v=VS.85%29.aspx"]WM_KEYDOWN[/url]

[url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms646286%28v=VS.85%29.aspx"]WM_SYSKEYDOWN[/url]

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this