Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Simulate Mouse Movement

This thread is locked; no one can reply to it. rss feed Print
Simulate Mouse Movement
TestSubject
Member #8,989
August 2007
avatar

Is a there a way, in C++ or Allegro, to simulate mouse movement on another document?

Say move the mouse up and down in Paint for 127 cycles?

Kikaru
Member #7,616
August 2006
avatar

I don't believe you can control a program from another like that. So, I'd say, no. Using save_bitmap and some drawing functions, you could make the same (more or less) result.

Hope that helps. :)

TestSubject
Member #8,989
August 2007
avatar

Ok, thanks.

Trent Gamblin
Member #261
April 2000
avatar

If you're using Windows, look at SendInput. It requires xp or later.

TeamTerradactyl
Member #7,733
September 2006
avatar

Are you talking about something that allows a program to control a mouse pointer anywhere, including "mouse move" and "mouse click" inside of other windows?

I know that it can be simulated, since VNC is built on that concept. However, some programs consider it an "artificial click" (programs like ZoneAlarm come to mind, where you can mash the mouse button as much as you want and still not click ZoneAlarm's "Accept/Deny" popup window buttons).

Was that what you were talking about, or did you mean inside your own Allegro game? Because if it's inside your own game, you can simply store the mouse_x or mouse_y values to another variable, then when you want to "ignore user input while you move the mouse programatically", simply ignore the current mouse inputs and instead, simulate the movement, and pass the results to whatever part of your program requires the new input.

Which one of these were you referring to (or was there a 3rd option not discussed here)?

Oscar Giner
Member #2,207
April 2002
avatar

There are programs to do this. They're called macros. Macro Express for example is a commercial one. You also have AC Tool, which is open source.

Tobias Dammers
Member #2,604
August 2002
avatar

Clicky
Not cross-platform though, but since you're talking about Paint, I assume Windows.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

TestSubject
Member #8,989
August 2007
avatar

I am checking out ACTool. Downloading now. For

VOID mouse_event(          DWORD dwFlags,
    DWORD dx,
    DWORD dy,
    DWORD dwData,
    ULONG_PTR dwExtraInfo
);

I could do...something like:
mouse_event(MOUSEEVENTF_ABSOLUTE,120,120)
for moving the mouse to (120,120)?

And yes, this is not inside a program.

Trent Gamblin
Member #261
April 2000
avatar

Here's how you do it with SendInput

1#include <windows.h>
2 
3void mouseMove(int dx, int dy)
4{
5 INPUT input;
6 
7 input.type = INPUT_MOUSE;
8 
9 input.mi.dx = dx;
10 input.mi.dy = dy;
11 input.mi.mouseData = 0;
12 input.mi.dwFlags = MOUSEEVENTF_MOVE;
13 input.mi.time = 0;
14 input.mi.dwExtraInfo = 0;
15 
16 SendInput(1, input, sizeof(INPUT));
17}

[edit]

I attached a program that is part of another program I wrote, that does it from the command line. It can do mouse button presses and releases and key events too. e.g.

MoccaInput mouseMove 10 10 // move the mouse 10 pixels down and to the right
MoccaInput mouseButton 2 // press left mouse button
MoccaInput mouseButton 4 // release left mouse button
MoccaInput keyDown 13 // Press enter
MoccaInput keyUp 13 // Release enter

The mouse buttons are:
2 left down
4 left up
8 right down
16 right up
32 middle down
64 middle up

and the key codes are virtual key codes VK_* defined in winuser.h.

Tobias Dammers
Member #2,604
August 2002
avatar

Quote:

MoccaInput mouseMove 10 10 // move the mouse 10 pixels down and to the right
MoccaInput mouseButton 2 // press left mouse button
MoccaInput mouseButton 4 // release left mouse button
MoccaInput keyDown 13 // Press enter
MoccaInput keyUp 13 // Release enter

So you can script all kinds of input events from the command line?
evil grin

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Trent Gamblin
Member #261
April 2000
avatar

It's part of a program that controls your pc from a mobile phone. The pc app is written in java, and I got tired of fighting with JNI (couldn't get it to work) so I just made a command line program :P

Go to: