Discussion:
Determining Left ALT
(too old to reply)
NickP
2006-03-16 10:36:51 UTC
Permalink
Hi there,

I'm using the following to determin if Left ALT is currently down,

if(GetAsyncKeyState(VK_LMENU)!=0)

For some reason it's only working with the right ALT key though... Am I
checking this the right way? Cheers in advance.

Nick.
David Lowndes
2006-03-16 17:21:56 UTC
Permalink
Post by NickP
I'm using the following to determin if Left ALT is currently down,
if(GetAsyncKeyState(VK_LMENU)!=0)
For some reason it's only working with the right ALT key though... Am I
checking this the right way? Cheers in advance.
Nick,

Check the top bit is set - that's what the documentation says to do.

if ( GetAsyncKeyState(VK_LMENU) & 0x8000 )


Dave
NickP
2006-03-16 17:35:27 UTC
Permalink
Hi David,

I had tried that too at one point, and still no luck, I just get beeped
at by the PC speaker, would that mean something else is getting focus when
ALT is pressed? The window that this is being trapped in contains no
standard Win32 controls at all, I can trap the right ALT perfectly but not
the left. Any ideas? Cheers for your help, much appreciated.

Nick.
Post by David Lowndes
Post by NickP
I'm using the following to determin if Left ALT is currently down,
if(GetAsyncKeyState(VK_LMENU)!=0)
For some reason it's only working with the right ALT key though... Am I
checking this the right way? Cheers in advance.
Nick,
Check the top bit is set - that's what the documentation says to do.
if ( GetAsyncKeyState(VK_LMENU) & 0x8000 )
Dave
David Lowndes
2006-03-16 20:19:20 UTC
Permalink
Post by NickP
I had tried that too at one point, and still no luck, I just get beeped
at by the PC speaker, would that mean something else is getting focus when
ALT is pressed? The window that this is being trapped in contains no
standard Win32 controls at all, I can trap the right ALT perfectly but not
the left. Any ideas?
Nick,

You'll need to explain a bit more about your situation.

Dave
NickP
2006-03-17 09:20:41 UTC
Permalink
Hi Dave,

Well the application is basically just an empty form with graphics being
drawn onto it with a combination of GDI / GDI+, so I have no standard Win32
controls on it. The only place that I'm actually checking for the ALT key
being pushed is in the main window handles message handler...

case WM_KEYUP:
{
int keyCode = (int)wParam;
switch (keyCode)
{
case VK_RETURN: //Return-Enter
{
if(GetKeyState(VK_LMENU) & 0x8000)
//Do stuff;

break;
}
}

break;
}

I can use VK_MENU, VK_LMENU or VK_RMENU but the only key that gets
detected is the right ALT. Maybe I should be just raising a flag on the
VK_LMENU keydown. I'll try a few things now.

Nick.
Post by David Lowndes
Post by NickP
I had tried that too at one point, and still no luck, I just get beeped
at by the PC speaker, would that mean something else is getting focus when
ALT is pressed? The window that this is being trapped in contains no
standard Win32 controls at all, I can trap the right ALT perfectly but not
the left. Any ideas?
Nick,
You'll need to explain a bit more about your situation.
Dave
NickP
2006-03-17 09:46:48 UTC
Permalink
Just to add....

case WM_KEYDOWN:
{
int keyCode = (int)wParam;
switch (keyCode)
{
case VK_LMENU: //Left ALT
{
MessageBox(NULL, "left POP!", "", 0);
break;
}
case VK_RMENU: //Right ALT
{
MessageBox(NULL, "right POP!", "", 0);
break;
}
case VK_PRIOR: //Page Up
{
MessageBox(NULL, "foobar!", "", 0);
break;
}
}
break;
}

Only Page Up gets detected in the keydown, where is ALT going?!

VK_MENU gets fired on Key Down but only with the Right ALT, not the Left...

Sorry to go on...

Nick

(For some really stupid reason I just accidently posted to the wrong group /
thread entirely.. stupid me!)
Post by NickP
Hi Dave,
Well the application is basically just an empty form with graphics
being drawn onto it with a combination of GDI / GDI+, so I have no
standard Win32 controls on it. The only place that I'm actually checking
for the ALT key being pushed is in the main window handles message
handler...
{
int keyCode = (int)wParam;
switch (keyCode)
{
case VK_RETURN: //Return-Enter
{
if(GetKeyState(VK_LMENU) & 0x8000)
//Do stuff;
break;
}
}
break;
}
I can use VK_MENU, VK_LMENU or VK_RMENU but the only key that gets
detected is the right ALT. Maybe I should be just raising a flag on the
VK_LMENU keydown. I'll try a few things now.
Nick.
Post by David Lowndes
Post by NickP
I had tried that too at one point, and still no luck, I just get beeped
at by the PC speaker, would that mean something else is getting focus when
ALT is pressed? The window that this is being trapped in contains no
standard Win32 controls at all, I can trap the right ALT perfectly but not
the left. Any ideas?
Nick,
You'll need to explain a bit more about your situation.
Dave
David Lowndes
2006-03-17 11:43:19 UTC
Permalink
Nick,

Note that the header file says:

/*
* VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
* Used only as parameters to GetAsyncKeyState() and GetKeyState().
* No other API or message will distinguish left and right keys in
this way.
*/

Additionally, the Alt key gives rise to a WM_SYSKEYDOWN message.

Spy++ is indispensable in these situations!

What are you really trying to achieve?

Dave
NickP
2006-03-17 11:58:57 UTC
Permalink
Hi Dave,
My apologies if I've missed something important, I try not to go
anywhere near those.
Post by David Lowndes
/*
* VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
* Used only as parameters to GetAsyncKeyState() and GetKeyState().
* No other API or message will distinguish left and right keys in
this way.
*/
Cool, I'm actually using GetKeyState() at the moment, the Async one
didn't work all of the time.
Post by David Lowndes
Additionally, the Alt key gives rise to a WM_SYSKEYDOWN message.
Spy++ is indispensable in these situations!
Aah, I shall have to take a look at that then and see if I can raise a
flag off the back of it.
Post by David Lowndes
What are you really trying to achieve?
Just detect a Left ALT + (Enter / Return) at the moment and process
some code from it. Basically just to flip between 2 different display modes
in the application.

I'll take a look at WM_SYSKEYDOWN now...

Thanks for your help, It's really appreciated and really helpful too.

Nick.
NickP
2006-03-17 12:16:42 UTC
Permalink
Hi again Dave,

That's got it!

case WM_SYSKEYDOWN:
{
int keyCode = (int)wParam;
switch (keyCode)
{
case VK_RETURN: //ALT + Enter / Return
{
//Do code here!
return(0);
break;
}
}
break;
}

Cheers for your help, great stuff.

Nick.
Post by David Lowndes
Nick,
/*
* VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
* Used only as parameters to GetAsyncKeyState() and GetKeyState().
* No other API or message will distinguish left and right keys in
this way.
*/
Additionally, the Alt key gives rise to a WM_SYSKEYDOWN message.
Spy++ is indispensable in these situations!
What are you really trying to achieve?
Dave
Loading...