I have a GUI and I want to repeat some process from the time the given key is pressed until the key is released.
I know how to do some process once when the key is pressed. But is there any way how to for example display random number every second until the key is released?
Thank you for your answers. Jaja
You can attach a timer to your figure, start it with the
KeyPressFcnand stop it with theKeyReleaseFcn.The example below will create a figure, and display a random number in the console as long as the key f is pressed.
This is a simple timer mode and the callback function take a lot less time than the interval so no problem to expect here. If you want whatever function to re-execute itself right after it's finished (kind of infinite loop), you can set that up by changing the
executionmodeof the timer (read thetimerdocumentation for examples.However, be aware that if your callback execute permanently and consume all the (matlab unique) thread ressource, your GUI might become less responsive.