Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulating mouse movement (C#)

Tags:

c#

mousemove

How would I go about making a small program that keeps moving the mouse upwards?


For those who would like to know, tt's a tiny one-use thing. I'm playing Star Wars The Force Unleashed. In console versions, you would hold the right stick upwards. In the bad console port on the PC, you're using your mouse. Maybe you can understand my frustration.

like image 886
Vivelin Avatar asked Nov 27 '22 01:11

Vivelin


2 Answers

SetCursorPos will do this in unmanaged code. I'm not sure if there's a .NET method to do the same, but you can always use com interop. It's in User32.dll

[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);

a little google produces this as a SetCursorPos equivalent for .net

System.Windows.Form.Cursor.Position
like image 172
John Knoeller Avatar answered Dec 24 '22 00:12

John Knoeller


This is a problem for mechanical programming, not CSharp.

  • You need to plug in a second mouse, and get a cheap variable speed corded drill.
  • Put a sanding drum on the drill, wrap it with striped paper, and set it to the lowest speed.
  • Then put a bracket on the non-rotating body of the drill that will hold the mouse with its sensor close to the spinning striped paper.
  • Ensure the mouse is facing the right way to simulate an up movement.

To execute the program, flip the power switch on the power strip the drill is plugged into.

Edit: if you want more portable code, use a cordless drill. Batteries not included.

like image 26
jball Avatar answered Dec 24 '22 02:12

jball