6

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.

asked Dec 22, 2009 at 22:24
0

3 Answers 3

17

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
answered Dec 22, 2009 at 22:38
Sign up to request clarification or add additional context in comments.

4 Comments

This would certainly move the mouse. But would the game get the proper indication the mouse moved?
try it, it generates WM_MOUSEMOVE events as a side effect. (even if the mouse doesn't actually move, if I recall).
Well then this should do the trick without the need to find the window of the game.
yep, and it also won't result in the cursor being somewhere different from the last WM_MOUSEMOVE moessage that the game got
17

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.

answered Dec 22, 2009 at 23:00

1 Comment

It would certainly work but it's not exactly the answer I was hoping for. Thanks, though. ;)
3

I don't know the game but internally windows sends out messages for mouse move. These are sent by the SendMessage() API call to the application. In C# you would either have to use the same Win32 API directly or perhaps by creating/sending an event? Not sure how to send an event to another running application though.

The SendMessage() Win32 API call defined in C# would look like this:

[DllImport("user32.dll")]
 public static extern int SendMessage(
 int hWnd, // handle to destination window
 uint Msg, // message
 long wParam, // first message parameter
 long lParam // second message parameter
 );
John Rudy
38k14 gold badges67 silver badges101 bronze badges
answered Dec 22, 2009 at 22:32

3 Comments

This is about the only hope. The question is, how to get the handle to a running full-screen DirectX or OpenGL game.
I believe there is some API call to get all of the active windows on the system and their respective handles... maybe search for that?
-1 This is a BAD idea. WM_MOUSEMOVE messages are the final step of a complex interaction between pulling a raw mouse_move event off of the queue and several messages to the window proc including WM_NCHITTEST and WM_SETCURSOR. Bypassing these other messages will break applications that have even slightly sophisticated mouse handling.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.