• Advertisement
Sign in to follow this  

[.net] Getting VK_LSHIFT & VK_RSHIFT from WM_KEYDOWN

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

I'm using an IMessageFilter in my .NET-based game to capture certain window messages (mostly WM_INPUT, WM_CHAR and WM_KEYUP/DOWN). Pretty simple stuff:


internal class WindowMessageFilter : IMessageFilter, IDisposable {
public WindowMessageFilter(IntPtr windowHandle) {
Application.AddMessageFilter(this);
}

bool IMessageFilter.PreFilterMessage(ref Message message) {
switch (message.Msg) {
case (int)UnsafeNativeMethods.WindowMessages.WM_KEYDOWN: {
int virtualKeyCode = message.WParam.ToInt32();
return true; // consumed!
}
}
return false;
}
}


According to MSDN, the VK_ code is provided in the wParam of a WM_KEYDOWN message. So far so good, but no matter whether I press the left or the right Shift key, the WM_KEYDOWN I receive reports only VK_SHIFT in its wParam, whereas I would prefer to get separate messages for VK_LSHIFT and VK_RSHIFT.

I've seen that bit 24 in lParam specifies whether it's the left or right shift key, so I could translate VK_SHIFT and VK_CONTROL to the left/right-distinguishing equivalents manually, but is that the only way to arrive at the VK_LSHIFT/VK_RSHIFT messages? Or is there some flag or mode I can set to tell Windows to provide me with the latter?

Share this post


Link to post
Share on other sites
Advertisement
According to MSDN the VK_LSHIFT and VK_RSHIFT are only available with some functions :

These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.[/quote]

You could try to add a check to GetKeyState(VK_LSHIFT) to distinguish between the two.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement