How do I make the mouse cursor move at a custom rotation angle?

41 views (last 30 days)
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
Shikhar Vats
Shikhar Vats on 28 Mar 2017
Walter: I misread your question, the appearance of cursor doesn't matter, it is the path that the cursor moves that needs to be rotated. SO for example, if the angle is 90 degrees, the cursor appears to move vertically when I move my mouse horizontally.
Shikhar Vats
Shikhar Vats on 29 Mar 2017
Edited: Shikhar Vats on 29 Mar 2017
Update: So I have been trying out a few other options. One of them being is similar to what Jan mentioned: Making the original cursor visible and have a pseudo code.
currentPoint = get (gca, 'CurrentPoint');
x0 = currentPoint(1,1);
y0 = currentPoint(1,2);
screenSize = get(0, 'screensize');%the size of screen
x_start = screenSize(3)/2;
y_start = screenSize(4)/2;
r = 30;
R = 250;
rot = 10;
y_target = R*sin(pi/2)+y_start;
x_target = R*cos(pi/2)+x_start;
%%Mouse moves into the initial circle
if (x0-x_start).^2+(y0-y_start).^2<(0.5*r).^2
tic;
start_flag = true;
pause(2);
target.FaceColor = 'g';
startTime = (clock);
num = 1;
num2 = 1;
x_group(num) = x0;
y_group(num) = y0;
x_group2(num2) = x0;
y_group2(num2) = y0;
else
%%Mouse starts moving from the initial circle
num = num+1;
x_group(num) = x0;
y_group(num) = y0;
%%Calculation of the new route
x_new = (x0-x_group(num-1))*cos(rot*pi/180)-(y0-y_group(num-1))*sin(rot*pi/180)+x_group2(num2);
y_new = (y0-y_group(num-1))*cos(rot*pi/180)+(x0-x_group(num-1))*sin(rot*pi/180)+y_group2(num2);
num2 = num2+1;
x_group2(num2) = x_new;
y_group2(num2) = y_new;
hold on;
plot_orig(num2) = plot(x0,y0,'^g');
% set(plot_orig(num2-1),'Visible','off');
plot_new(num2) = rectangle('Position',[x_new-0.5*10,y_new-0.5*10,10,10],'Curvature',[1,1], 'FaceColor','b');
delete (plot_new(num2-1));
if sqrt((x_new-x_start).^2+(y_new-y_start).^2) > 250
start_flag = false;
time_session = toc;
target.FaceColor = 'r';
end
end
This almost solves my purpose except for one problem, it shows an error(Cannot access method 'delete' in class 'matlab.ui.Root'.) in the delete(plot_new(num2-1) and randomly plots a blue circle during the path. I can't figure out how to go about solving it.
The pink circle is the starting point, red is the target and blue is the rotated mouse cursor. The green shows the original path
@Star Strider: You are correct, this is meant for the same psychology experiment which is a part of our research.

Sign in to comment.

Answers (1)

Jan
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
Shikhar Vats
Shikhar Vats on 29 Mar 2017
Edited: Shikhar Vats on 29 Mar 2017
Update: So I have been trying out a few other options. One of them being is similar to what Jan mentioned: Making the original cursor visible and have a pseudo code.
currentPoint = get (gca, 'CurrentPoint');
x0 = currentPoint(1,1);
y0 = currentPoint(1,2);
screenSize = get(0, 'screensize');%the size of screen
x_start = screenSize(3)/2;
y_start = screenSize(4)/2;
r = 30;
R = 250;
rot = 10;
y_target = R*sin(pi/2)+y_start;
x_target = R*cos(pi/2)+x_start;
%%Mouse moves into the initial circle
if (x0-x_start).^2+(y0-y_start).^2<(0.5*r).^2
tic;
start_flag = true;
pause(2);
target.FaceColor = 'g';
startTime = (clock);
num = 1;
num2 = 1;
x_group(num) = x0;
y_group(num) = y0;
x_group2(num2) = x0;
y_group2(num2) = y0;
else
%%Mouse starts moving from the initial circle
num = num+1;
x_group(num) = x0;
y_group(num) = y0;
%%Calculation of the new route
x_new = (x0-x_group(num-1))*cos(rot*pi/180)-(y0-y_group(num-1))*sin(rot*pi/180)+x_group2(num2);
y_new = (y0-y_group(num-1))*cos(rot*pi/180)+(x0-x_group(num-1))*sin(rot*pi/180)+y_group2(num2);
num2 = num2+1;
x_group2(num2) = x_new;
y_group2(num2) = y_new;
hold on;
plot_orig(num2) = plot(x0,y0,'^g');
% set(plot_orig(num2-1),'Visible','off');
plot_new(num2) = rectangle('Position',[x_new-0.5*10,y_new-0.5*10,10,10],'Curvature',[1,1], 'FaceColor','b');
delete (plot_new(num2-1));
if sqrt((x_new-x_start).^2+(y_new-y_start).^2) > 250
start_flag = false;
time_session = toc;
target.FaceColor = 'r';
end
end
This almost solves my purpose except for one problem, it shows an error(Cannot access method 'delete' in class 'matlab.ui.Root'.) in the delete(plot_new(num2-1) and randomly plots a blue circle during the path. I can't figure out how to go about solving it.
The pink circle is the starting point, red is the target and blue is the rotated mouse cursor. The green shows the original path
@Star Strider: You are correct, this is meant for the same psychology experiment which is a part of our research.
Star Strider
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.

Sign in to comment.

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!