how get the real pos

i use the script to get mouse pos in simlink window but in 2024b it fail ,i want to know how to fix it,thanks
function pos = saGetMousePosition
mousePosition = get(0,'PointerLocation');
locationBase = get_param(gcs,'Location'); % Screen Left-Top [0 0], and always gets valid value on different screens
scrollOffset = get_param(gcs,'ScrollbarOffset');
screenSize = get(0,'ScreenSize');
zoomFactor = str2double(get_param(gcs, 'ZoomFactor'))/100;
% Calculate new position
p_X = ceil((mousePosition(1) - locationBase(1) + scrollOffset(1))/zoomFactor);
p_Y = ceil((screenSize(4) - mousePosition(2) - locationBase(2) + scrollOffset(2))/zoomFactor);
pos = [p_X, p_Y];
end

2 Comments

dpb
dpb on 12 Jan 2026
"...but in 2024b it fail[s]"
For what definition of failure? Does it return an error, wrong values, something else...???
ads
ads on 13 Jan 2026
Sorry, I didn't describe it clearly., i use this script to get the mouse pos in simlink ,it did work in 2022b can return the correct pos, ,but i it return wrong pos in 2024b like this picture you can see the gain is not create in mouse pos ,thanks again.

Sign in to comment.

Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products

Tags

Asked:

ads
on 12 Jan 2026

Commented:

ads
on 13 Jan 2026

Community Treasure Hunt

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

Start Hunting!