Trouble reading Keyboard

Started by
-1 comments, last by Slider38 22 years, 11 months ago
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

This topic is closed to new replies.

Advertisement