Can anybody fix this problem about GUI and mouse position please?

조회 수: 1 (최근 30일)
Ara
Ara 2014년 8월 8일
댓글: Ara 2014년 8월 8일
I want to find the position of mouse in anywhere of screen in GUI.
C = get(0,'PointerLocation'); I knew that this code can find any position on screen and then I use it with GUI but it didn't work.
this following is my code.
function mouse()
f=figure; set (f, 'WindowButtonDownFcn', @mouseMove); % by click
function mouseMove (hObject,~)
C = get(0,'PointerLocation'); title(['(X,Y) = (', num2str(C(1,1)), ', ',num2str(C(1,2)), ')']);
  댓글 수: 1
Andy L
Andy L 2014년 8월 8일
You want the mouse position for anywhere on the screen, not just in the GUI?

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

답변 (1개)

Andy L
Andy L 2014년 8월 8일
편집: Andy L 2014년 8월 8일
Firstly You need to add end statements to each function. See the following documentation on local functions.
function [out1] = name(in1)
% some code
in2 = in1;
[out2] = subFunction(in2);
out1 = out2;
end
function [out2] = subFunction(in2)
% some other code
end
Next you are setting the property to the handle of the figure - this means your callback to mouseMove will only execute whilst your cursor is over the figure. To do what you are asking you would need to set the function for the root object.
However i'm not sure if this is possible based on the documentation - Root Object Properties.
  댓글 수: 3
Andy L
Andy L 2014년 8월 8일
편집: Andy L 2014년 8월 8일
See my revised answer.
Ara
Ara 2014년 8월 8일
Thank you. I'm trying to understand :)

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

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by