How can I compress the button motion events?

3 visualizzazioni (ultimi 30 giorni)
Naum Derzhi
Naum Derzhi il 9 Giu 2021
Risposto: Swastik Sarkar il 28 Feb 2024
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

Risposte (1)

Swastik Sarkar
Swastik Sarkar il 28 Feb 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.

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by