How do I make the mouse cursor move at a custom rotation angle?
Afficher commentaires plus anciens
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 commentaires
Jan
le 27 Mar 2017
It's not completely clear to me. Do you mean: When the defined angle is 90 deg, you want that the mouse cursor moves vertically, when the user moves the mouse horizontally?
This can be achieved easily by rotating the mouse :-)
John BG
le 27 Mar 2017
Shikhar wants to automate mouse rotation with a script, the question couldn't be clearer
Walter Roberson
le 27 Mar 2017
John BG: does Shikhar Vats want to pre-record a cursor path and then replay the cursor movement with the path rotated around some point? Or does Shikhar Vats want to input the angle and then have live cursor movement have its path rotated around some point? Which point does Shikhar Vats want the path to be rotated with respect to? Or does Shikhar Vats want the appearance of the cursor to be rotated but the positioning to be left alone?
Shikhar Vats
le 28 Mar 2017
Modifié(e) : Shikhar Vats
le 28 Mar 2017
Walter Roberson
le 28 Mar 2017
Shikhar Vats: do you want the path of movement to be rotated? Or do you want the cursor movement to be left alone, but for example the arrow cursor would tilt? For example some of the directions are shown at https://unicode-table.com/en/sets/arrows-symbols/
@Shikhar Vats: Sorry, my "rotating the mouse" meant to rotate the physical device. This is very fast, trivial and does not need any software. But I can imagine that it does not satisfy your needs and I meant this with humor. (Nevertheless, it would solve the problem immediately :-) )
Shikhar Vats
le 28 Mar 2017
Shikhar Vats
le 29 Mar 2017
Modifié(e) : Shikhar Vats
le 29 Mar 2017
Réponses (1)
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 commentaires
Guillaume
le 29 Mar 2017
As far as I know matlab does not expose the mechanism to capture mouse movement outside of a figure. So, within matlab the only way to capture mouse movement over the entire screen is to make the window fullscreen.
I would suspect that listening to the mouse movement event and changing the mouse position after it's effectively been moved by the OS is never going to work very well and most likely will result in the cursor jumping around. To do this properly, you'd have to write a filter driver something you can't do in matlab.
Note: this applies to Windows. Don't know anything about other OSes.
Jan
le 29 Mar 2017
@Shikhar: Do you really need the mouse to move messed up? Or would it be enough to set the original mouse cursor invisible and rendering a pseudo cursor which looks like the mouse is moved in a rotated angle?
Perhaps your problem can be solved with other methods. Please explain more details.
Star Strider
le 29 Mar 2017
This seems to be an interesting psychology experiment (or skillful prank).
With respect to the psychology experiment, it would be interesting to see how long it takes a subject to discover the ‘problem’ and learn to manipulate the mouse to achieve the desired objective, for example to pursue a moving object.
@Star Strider: A colleage has pressed the hot key for rotating the screen by 180 deg by accident. He was not able to use the mouse to select the context menu on the desktop to rotate the screen again. He even tried to look from above to the monitor while standing behind it. After minutes of desperation and a lot and laughing I revealed the trivial trick: Rotate the mouse by 180 deg also, then it moves in the expected direction again. :-)
Do you remeber Apple's USB mouse? The round shape allows to identify the orientation by the position of the key only with perhaps a deviation of 10 deg. But it took less then a centimenter of movement to know exactly where "up" is amd to adjust the motion.
Shikhar Vats
le 29 Mar 2017
Modifié(e) : Shikhar Vats
le 29 Mar 2017
Star Strider
le 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.
Catégories
En savoir plus sur TCP/IP Communication dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

