Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Slider38

Trouble reading Keyboard

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

Hi Folks, I am trying to read up to 3 numbers input by the user. The theory here is that the user will signify they are finished by hitting the enter key. My problem is that every time I hit a key it is being read multiple times. I''ve tried all kind of things to fix it and have not been successful. done is a global initialized to 0. kup is a global bool initialized to true. A little of the code: if(done==0) { if(kup==true) { lpdikey->GetDeviceState(256, (LPVOID)keystate); if(keystate[DIK_0] & 0x80) { keyread = 0; kup = false; } if(keystate[DIK_1] & 0x80) { keyread = 1; kup = false; } This goes on thru 9, followed by this: if(keystate[DIK_RETURN] & 0x80) keyread = 9999; } keyread is a global as is done. I also have globals setup to keep track of each of the numbers input as dataread1, dataread2, and dataread3. These are initialized to 99. The code continues like this: if(kup == false) { hres = lpdikey->GetDeviceState(256, (LPVOID)keystate); if(hres==NULL) kup = true; } I am trying to use this code to insure that the key is no longer being pressed before I make these assignments. if((kup)&&(dataread1 == 99)) { dataread1 = keyread; keyread = 99; } if((kup)&&(dataread1 != 99)&&(keyread != 99)) { dataread2 = keyread; keyread = 99; } if((kup)&&(dataread1 != 99)&&(dataread2 != 99)&&(keyread != 99)) { dataread3 = keyread; keyread = 99; } if((kup)&&(keyread == 9999)) done =1; keyread = 99; If anyone has an idea as to why this won''t work, I''d appreciate a suggestion. I have no problem getting the first input assigned to dataread1, but dataread2 is also getting assigned the same value. I''ve tried a variety of things to try and insure that the key is no longer being pressed before assigning the resulting keyread value to my dataread variables. I''ve also tried a number of assignment statements. At this point, after a couple of weeks of fooling with this code, I''m not sure I could see the error if it smacked me in the kisser. Thanks folks, Slider

Share this post


Link to post
Share on other sites
Advertisement

  • 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!