How can I compress the button motion events?
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Swastik Sarkar
2024-2-28
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!