Effacer les filtres
Effacer les filtres

Determine if any key is being pressed

14 vues (au cours des 30 derniers jours)
Jacob Cooley
Jacob Cooley le 11 Nov 2021
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?

Réponses (1)

Rafael Hernandez-Walls
Rafael Hernandez-Walls le 12 Nov 2021
If only use the function:


En savoir plus sur Strategy & Logic dans Help Center et File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by