Jump to content
  • Advertisement
Sign in to follow this  
Mantear

WM_KEYDOWN and the Alt key [solved]

This topic is 4366 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

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!