Checking every key has been released before changing screen colour

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Checking every key has been released before changing screen colour

Anon1232
Hi, im working on project 4 and trying to make it so the screen dosent change colour till every key has been relesed. The problem I have is that the screen changes colour when I release a key, even if I have a second key pressed. How would you make it so the code checks to make sure no keys are pressed. Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Checking every key has been released before changing screen colour

WBahn
Administrator
The keyboard buffer should have a non-zero code if any key is being pressed. If you have more than one key pressed, it's difficult to say what that code will be.

It's possible that as you release a key, while others are held, that you get a zero value briefly as the interface logic recognizes that something has changed. I don't know that this is the case.

Some experimentation should determine if that is the case and, if it is, then there are a few ways to deal with it.
Reply | Threaded
Open this post in threaded view
|

Re: Checking every key has been released before changing screen colour

Anon1232
Hi, thanks for the reply. The value does become zero briefly untill it realizes your still holding a key. Is there any way to deal with this?
Reply | Threaded
Open this post in threaded view
|

Re: Checking every key has been released before changing screen colour

WBahn
Administrator
One way is to require that the value remain zero for some minimum amount of time before acting on it. This can be done using a counter. Say you determine that the longest it will remain zero is the amount of time it takes to run through your loop that checks it 12 times. So you can set a counter up and any time you check the keyboard and it is not zero, you set the counter to zero. Then when you check the keyboard and it is zero, you increment the counter. If the counter is less that, say, 15, you do nothing more. But as soon as it hits 15 you now do whatever you want done when no keys are pressed.
Reply | Threaded
Open this post in threaded view
|

Re: Checking every key has been released before changing screen colour

Anon1232
Ill give that a try, thanks