How do I rotate a 2 dimensional shape using my computer's arrow keys?

4 views (last 30 days)
Hello, I am trying to create a version of Asteroids where the ship is centered in the middle and can rotate around the center of a grid. I was wondering if it would be possible to use the computer's arrow keys to drive the rotation ie, left arrow to turn clockwise, right arrow to turn counter clockwise. I appreciate the help!

Answers (2)

Rik
Rik on 14 Feb 2018
You can use the KeyPressFcn, KeyReleaseFcn, WindowKeyPressFcn and WindowKeyReleaseFcn callbacks of a figure to catch the keys being pressed (you also need to set the first two to any panels, axes or disabled uicontrols there are in your GUI). The rest of the implementation depends on your specifics.

Jan
Jan on 14 Feb 2018
Edited: Jan on 14 Feb 2018
You find some examples of catching the currently pressed key in the FileExchange: FEX: Search for "keypress" .
By the way: There is an Asteroids version submitted as example for KeyPressFcn and WindowButtonMotionFcn also.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!