How can I compress the button motion events?

2 vues (au cours des 30 derniers jours)
Naum Derzhi
Naum Derzhi le 9 Juin 2021
I attach a callback to WindowButtonMotion event to track the cursor location. The code is doing some stuff in response to mouse movement, and the events are quiing up faster than the code can react tot them. I need to discard the events accumulated while the callback was executed and pickup only the next event occuring after the callback is done. In some systems this is called "event compression". However, I did not find anything similar in Matlab.
Any ideas will be appreciated.
I can, of course, detach the callback until it's done and then reattach it, but this seems to be inelegant. Are there any better solutions?
Thank you

Réponses (1)

Swastik Sarkar
Swastik Sarkar le 28 Fév 2024
It seems you are looking to apply Event Compression within a MATLAB figure, aiming to ensure that only the most recent event is processed while discarding others, much like a mutex mechanism in programming.
Here is a MATLAB code example that initiates a MATLAB figure which you can build upon to incorporate event compression:
f = figure();
f.WindowButtonMotionFcn = @(fig, eve) btnCb(fig);
f.UserData.isBusy = false;
function btnCb(fig)
if fig.UserData.isBusy
return;
end
fig.UserData.isBusy = true;
currentPoint = get(fig, 'CurrentPoint');
disp(num2str(currentPoint(1,2)) + ", " + num2str(currentPoint(1,2)));
pause(1); % Simulation of high compute task.
fig.UserData.isBusy = false;
end
I hope this serves as a helpful starting point for your implementation.

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by