Can I define a figure event callback that triggers when the mouse enters/leaves the figure window?

조회 수: 7 (최근 30일)
I would like to know, if I can set up a callback function that is triggered when the mouse cursor leaves or enters the figure window.
function MouseEnteredWindowFcn(hObject, evData)
% do something when the mouse enters the window
end
function MouseLeftWindowFcn(hObject, evData)
% do something when the mouse leaves the window
end
I found MouseEnteredCallback on undocumentedmatlab.com. But I would rather use a more official method with less underlying Java components.
  댓글 수: 1
Rik
Rik 2022년 6월 8일
If you want official things only, you will have to track the cursor with the motion functions, or have a timer that test the position of the cursor periodically.

댓글을 달려면 로그인하십시오.

답변 (1개)

Poorna
Poorna 2023년 9월 7일
Hi Florian Berzsenyi,
I understand that you want to know if there are callback properties of mouse enter and exit events in the figure object. But as of R2023a there are no such properties.
You could achieve the required functionality by using WindowButtonMotionFcn, CurrentPoint,Position” properties of figure to detect mouse enter and exit events.
You can maintain a Boolean variable which takes the value true if the pointer is within the window in the previous call to the callback function, or false otherwise. Inside the callback function for WindowButtonMotionFcn, check if the CurrentPoint is within the bounds of the window, if this is true and the if the Boolean variable is false, it means the mouse pointer has just entered the window and you can perform your required operations for mouse entering the window. You could do the same for mouse leaving the window.
Hope this helps!

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by