tags:

views:

844

answers:

4

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.

+2  A: 

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
              );
Christian Vik
This is about the only hope. The question is, how to get the handle to a running full-screen DirectX or OpenGL game.
John Rudy
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?
Earlz
-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.
John Knoeller
+1  A: 

Did you try using a controller or joystick?

http://www.merconnet.com/product%5Finfo.php?products%5Fid=44

Woot4Moo
+4  A: 

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
John Knoeller
This would certainly move the mouse. But would the game get the proper indication the mouse moved?
Corin
try it, it generates WM_MOUSEMOVE events as a side effect. (even if the mouse doesn't actually move, if I recall).
John Knoeller
Well then this should do the trick without the need to find the window of the game.
Corin
yep, and it also won't result in the cursor being somewhere different from the last WM_MOUSEMOVE moessage that the game got
John Knoeller
I will try this when I've got the time, thanks.
horsedrowner
+5  A: 

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.

jball
Borat: Wowowuuuja!
Hamish Grubijan
+1 for thinking outside the box
Jagd
It would certainly work but it's not exactly the answer I was hoping for. Thanks, though. ;)
horsedrowner