Determine if any key is being pressed

조회 수: 17 (최근 30일)
Jacob Cooley
Jacob Cooley 2021년 11월 11일
답변: Rafael Hernandez-Walls 2021년 11월 12일
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;
end
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?
Thanks

답변 (1개)

Rafael Hernandez-Walls
Rafael Hernandez-Walls 2021년 11월 12일
If only use the function:
pause

카테고리

Help CenterFile Exchange에서 Strategy & Logic에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by