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

3 visualizaciones (últimos 30 días)
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 comentario
Rik
Rik el 8 de Jun. de 2022
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.

Iniciar sesión para comentar.

Respuestas (1)

Poorna
Poorna el 7 de Sept. de 2023
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!

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by