How do I make the mouse cursor move at a custom rotation angle?
41 views (last 30 days)
Show older comments
I want to make the mouse cursor move at a custom rotated angle. The idea is to input the angle of rotation form the user, then apply the rotation to the original path of the mouse cursor movement. Any help would be appreciated.
8 Comments
Answers (1)
Jan
on 28 Mar 2017
Edited: Jan
on 29 Mar 2017
This does not work:
function myMouseTest % FAILING!!!!!!!!
Alpha = 90 * pi / 180;
Rotation = [cos(Alpha), -sin(Alpha); sin(Alpha), cos(Alpha)];
FigH = figure('WindowButtonMotionFcn', {@myMouseCheater, Rotation});
setappdata(FigH, 'oldMousePos', get(groot, 'Pointerlocation'));
drawnow;
end
function myMouseCheater(FigH, EventData, Rotation) % FAILING!!!!!!!!
oldScreenPos = getappdata(FigH, 'oldMousePos');
curScreenPos = get(groot, 'Pointerlocation');
Moved = curScreenPos - oldScreenPos;
newScreenPos = oldScreenPos + Moved * Rotation;
set(groot, 'Pointerlocation', newScreenPos);
setappdata(FigH, 'oldMousePos', newScreenPos);
end
Currently, I can test this in a virtuial machine only. There setting the pointer location by get(groot, 'Pointerlocation') does not work. I post it here, because it might be useful for others to play around.
By the way:
Robby =java.awt.Robot;
Robby.mouseMove(10, 100);
does not work also: It has no effect to the position of the mouse cursor, but it affects the mouse style (e.g. set to the arrows, when the position would be on the corner of a window). It is a VMWare 7.1.4 with a Win7/64 Enterprise guest OS.
[EDITED] When working on the desktop directly, the moving works, but I do not find a way to store the old coordinates when the mouse cursor is outside the figure. I the mouse is moved out of the window e.g. in the top right corner, the last position inside the window is stored. When the mouse enters the window again at teh bottom left corner, the WindowButtonMotionFcn thinks, that the mouse has been move in on setp along teh diagonal. Currently I do not know how to solve this.
This problem will not appear for a maximized figure, which covers the full screen. Please explain more details, Shikhar.
6 Comments
Star Strider
on 29 Mar 2017
Fortunately, I have not done that myself!
I do not remember it. I agree with the Wikipedia article that it would be a significant human-factors design error. My first (and last) Apple machine was an Apple ][ that I bought in 1979 (and now have in storage). I have used MS-DOS and Windows PCs since 1985, because they were ‘open source’ and all the devices and software was written for them, and not Apple machines.
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!