Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

Question about while not mouseclick/keyboard input

+12 votes
I have been working with keyboard input and while loops. I want to change the panel every time the user clicks a key with the !panel.checkMouseClicked() and !panel.checkKeyboardInput. My problem is after the first page it stops working because it has the check as true. Does anyone know why this might be or how I might fix it?
asked Oct 24, 2016 in CSC 211 (F16) by Jack Cannell (437 points)

1 Answer

+1 vote
 
Best answer

After having done checkKeyboardInput(), you need to actually get the key (using getKeyboardInput()), in order to process that key, and have checkKeyboardInput() return false the next time.  I suspect that's your issue.  (Side note: you can also call the clearKeyboardInputQueue() method, which is useful if someone has been holding down on a key and a whole bunch of keystrokes have gotten "backed up" like a traffic jam in the pipeline...)

The situation is different for the checkMouseClicked() function, which will just return true once, before switching back to false (unless the user clicks the mouse again).

answered Oct 25, 2016 by Forrest Stonedahl (3,438 points)
selected Oct 25, 2016 by Jack Cannell
...