How to determine the position of the mouse anywhere on the screen?

I work in MATLAB and I want to get the cursor position from anywhere on the screen.

I want to constantly get the cursor position while moving the mouse. However, I found that MATLAB can get the mouse position while the mouse moves only in the graphical interface.

How can I achieve the same, but not in the GUI in MATLAB?

+4
source share
1 answer

Are you sure MATLAB can get mouse coordinates only in the graphical interface? It’s actually quite simple to get your mouse position anywhere on the screen, regardless of the graphical interface.

Use the following:

get(0, 'PointerLocation')

, . , . , GUI.

, x , - y . , . , (1,1), .

, , , while , CPU, :

while condition
    loc = get(0, 'PointerLocation');

    %// Do something
    %...
    %...

    pause(0.01); %// Pause for 0.01 ms
end
+6

Source: https://habr.com/ru/post/1570263/


All Articles