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
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
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!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!