Matlab 'get' function and detecting user mouse click
108 次查看(过去 30 天)
显示 更早的评论
I am using the get function to retrieve the mouse position like this:
get(0,'PointerLocation');
I also need to detect when a mouse button has been clicked. I've tried searching everywhere I know to search for this and cannot find how to do it. I also can't really find everything the get function can do (such as PointerLocation or ScreenSize, etc).
I'm using the java robot in other places in my code to move the mouse and get screen pixel colors. Is there any java functionality that will detect mouse clicks? Is there good documentation on what other java functionality there is for matlab and how to use it (syntax)?
Thanks in advance
1 个评论
回答(1 个)
Dasharath Gulvady
2014-8-5
编辑:Dasharath Gulvady
2014-8-5
Brandon, This can be achieved using 'WindowButtonDownFcn' property of the figure object.
Here is a demo code for the same:
function demo()
figure('WindowButtonDownFcn',@callBack)
function callBack(hObject,~)
mousePos=get(hObject,'CurrentPoint');
disp(['You clicked X:',num2str(mousePos(1)),', Y:',num2str(mousePos(2))]);
Hope this helps!
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!