Sign in to follow this  
Mantear

WM_KEYDOWN and the Alt key [solved]

Recommended Posts

Greetings, WIN32 and using VS 2005 Express. I'm running a program that is trying to capture all keyboard input. I've got everything working well except for the Alt key. In the LRESULT CALLBACK WndProc() method I'm capturing WM_KEYDOWN and WM_KEYUP's. However, the Alt key does not appear to get captured here. What am I going to have to do to capture the Alt key? Thanks! [Edited by - Mantear on October 8, 2006 4:00:44 PM]

Share this post


Link to post
Share on other sites
You can use the GetAsyncKeyState() function to grab it, if you like. The VK code is 'VK_MENU'. If you wish to tell between right and left alt presses, you can use 'VK_LMENU' or 'VK_RMENU'.

Example:
#include <iostream>
using namespace std;

int main()
{
while(!GetAsyncKeyState(VK_ESCAPE))
{
if(GetAsyncKeyState(VK_MENU))
{
cout << "Alternate key press was read... [";
if(GetAsyncKeyState(VK_LMENU)) cout << "LEFT]" << endl;
if(GetAsyncKeyState(VK_RMENU)) cout << "RIGHT]" << endl;
Sleep(200);
}
}
return 0;
}





Hope that helps.

[Edit:] Looking at MSDN right now, it appears that you can't grab the 'alt' key with WM_KEYDOWN, because you use lParam to see if 'alt' is being held at the same time as another key. (For keyboard shortcuts, I'd guess) Link
It's the same with WM_KEYUP.

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