Jump to content
  • Advertisement
Sign in to follow this  
Thunder_Hawk

Distinguishing Left and Right Shift Key Presses

This topic is 4871 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 having a hard time distinguishing between left and right shift key presses in Win32. I've been able to separate left and right alt and control presses through the extended key flag. However, this same situation obviously does not exist for the shift key. I attempted to use Get[Async]KeyState (VK_LSHIFT/VK_RSHIFT) to alleviate this snag, but in all of my testing, it always seems to return 0 regardless of what's being pressed. The only reason for this that I can think of is that my handling of keypresses is disrupting its proper operation. Here's what my keypress code looks like:
case WM_KEYDOWN:
  // update key state to an array
  if (alt or ctrl) {
    if (extended) // forward state to the right hand version
    else // forward state to the left hand version
  }
return 0;
// same for WM_KEYUP



Any ideas as to why GetKeyState isn't working as expected or what else I could do to differentiate left and right shift key presses?

Share this post


Link to post
Share on other sites
Advertisement
VK_LSHIFT and VK_RSHIFT are right. This works at my computer:
case WM_KEYDOWN: {
int key = int(wParam);
if(key == VK_LSHIFT) {
// left shift pressed
}
return 0;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by dali
VK_LSHIFT and VK_RSHIFT are right. This works at my computer:
case WM_KEYDOWN: {
int key = int(wParam);
if(key == VK_LSHIFT) {
// left shift pressed
}
return 0;
}


That definitely doesn't work on my computer, and according to MSDN, it shouldn't...

Share this post


Link to post
Share on other sites
I was under the impression that to listen for the shift/alt/ctrl keys you should be listening to WM_SYSKEYDOWN/WM_SYSKEYUP messages. It's been a while so I could be wrong.

Edit:
Keys - Seems I might have been wrong about the shift key (as I said, it's been a while) - but the link above might help you, it seems pretty comprehensive about the subject.

Share this post


Link to post
Share on other sites
Hmm, just tested some things on an XP machine and subsequently discovered that VK_L*/VK_R* are only supported for Windows NT or 2000 and later (I develop on a 98SE system).

*Investigates DirectInput*

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Who develops on a system no longer supported with security updates (this case Win9x). I hope you don't release anything to the wild (ie. Internet)! If you can get paid for it, donate some blood or something and buy say Windows 2000, it's cheap. Heck I seen XP Home for $40 at Fry's the other day (sale).

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Who develops on a system no longer supported with security updates (this case Win9x). I hope you don't release anything to the wild (ie. Internet)! If you can get paid for it, donate some blood or something and buy say Windows 2000, it's cheap. Heck I seen XP Home for $40 at Fry's the other day (sale).


lol, I have my reasons: keeping system requirements low and not being forced to buy a new computer are the major ones. Heck, I could get XP professional for the price of the CD if I wanted, but I don't think my system would be happy with me (433 Mhz CPU, 64 MB RAM, and 20 GB harddrive). I've never had any problems with security on it either, considering I set my firewall to block all windows services whenever I have an internet connection on it (which I don't right now) and am very selective about what sites I go to on it.

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!