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

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 日

1 投票

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 件のコメント

Ara
Ara 2014 年 8 月 8 日
編集済み: Ara 2014 年 8 月 8 日
Thank you very much for reply but I'm confuse and still don't understand how to get x,y position by pointing mouse when mouse is out of GUI area. I only get position when mouse is in GUI area.
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 :)

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGraphics Object Properties についてさらに検索

製品

質問済み:

Ara
2014 年 8 月 8 日

コメント済み:

Ara
2014 年 8 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by