Hey everone!!
Can any one please provide me with a code of keydown function and keypress function.
actually what i want to do is that when a specific key e.g. up arrow key is pressed, the ball starts moving in a circle and keeps on oving uptil the key is pressed.
as soon as that key is unpressed, the ball stops moving in a circle.
thanks in advance :)
In the above post, by 'stops moving', i intended to mean 'stops moving in a circle', and instead move in the tangential direction to the circular path. Hope it clarifies my problem.
@Andrew B: Thanks! I've implemented most of your suggestions. A new version should be up soon.
The "position" problem (if any) is, however, not easy to solve, as it seems to depend on OS, display setup, ML version ...
Great work.
I made a few tweaks which you may be interested in implementing.
I added the following properties to the figure:
'NumberTitle','off'
'position',[0 -40 1 1]
'Name','Press a key'
On Windows this places the figure off of the screen, instead of behind the taskbar. This will help ensure that the figure is not visible since some users may place their taskbar elsewhere on the screen.
It is also possible for the user to maximize the figure and then close it, which would cause an error when attempting to delete the figure handle. To procect against this use the following code:
if ishandle(fh)
delete(fh) ;
end
Thanks Jos. Do you know how I can detect keypresses of the left/right arrow keys? I know it must involve use of WindowKeyPressFcn but I have no idea how to use that in syntax, since there's no example for it in the Matlab help!
Comment only