Determine if any key is being pressed
6 views (last 30 days)
I am relatively new to matlab programming, I have a solid basis in Java, but am now learning matlab for an engineering class I am in.
In this class, we have to make a game in matlab, and my game involves taking user input to move a player sprite.
My game is supposed to run at 5 frames per second, and it works up until the point that I need to take user input.
The function I am using to determine what key the player is pressing waits until it sees an input for the user. This is fine when the user is pressing a key to move, however, I still need the game to run even if the player is not making input.
I basically want to have an if statement along these lines
if(a key is being pressed)
key = keyBeingPressed;
This would solve my issue, because keyBringPressed is the function that pauses the code until a key is pressed. However, if I only run that code when I know a key is being pressed, then if no key is being pressed the program will move past that point and will continue to run at the desired framerate.
Does anyone have a sugguestion for how to implement this?