Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Simulate Mouse Presses C++

Name: Anonymous 2011-10-28 17:29

I'm trying to write a program that at the underlying level simulates mouse events. The basic example of what I want it to do is move the mouse, press the mouse down, move the mouse again, and let mouse up to draw a line in say, MS Paint... or the Doodle or Die application (http://doodle.no.de);

The problem I run into is that neither Doodle or die nor MSPaint seem to accept that I am issuing mouse down events... except that MSPaint works fine if I am using a non drawing tool such as the Eraser or Selection.


int main(int argc, char *argv[])
{
    tagINPUT inp;
    tagMOUSEINPUT mi;
    DWORD moveFlags = (MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE);
    DWORD downFlags = (MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN);
    DWORD upFlags = (MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP);

    mi.dwFlags = moveFlags;
    mi.dx = 5000;
    mi.dy = 2000;
    inp.type = INPUT_MOUSE;
    inp.mi = mi;

    SendInput(1, &inp, sizeof inp);

    tagMOUSEINPUT mi2;
    tagINPUT inp2;

    SetCursorPos(1500, 500);

    mi2.dwFlags = downFlags;
    inp2.type = INPUT_MOUSE;
    inp2.mi = mi2;
    SendInput(1, &inp2, sizeof inp2);

    SetCursorPos(500,200);
    mi2.dwFlags = upFlags;
    inp2.type = INPUT_MOUSE;
    inp2.mi=mi2;
    SendInput(1, &inp2, sizeof inp2);
   
    return 0;
}


This was just really shit shod together code to try to get something working.

Basically, if MSPaint is up and I have the erase selected, it will erase a line from those 2 points like it should...but if I have the brush selected it will do nothing. Doodle or die (I believe is flash) does the same thing and will not draw.

I'm using windows.h's SendInput, however I have tried the deprecated mouse_event and it does the same thing.

Any ideas on how to get it to actually accept my leftDown and leftUp events?

Name: Anonymous 2011-10-28 21:43

Use AutoHotkey FFI to callback into your program,
returning commands to be interpreted:

http://www.autohotkey.com/docs/commands/DllCall.htm
http://www.autohotkey.com/docs/Functions.htm#NumPut
http://www.autohotkey.com/docs/commands/MouseClickDrag.htm

The script part:

TYPE_MOUSEMOVE := 0
TYPE_MOUSEDRAG := 1
TYPE_QUIT := 2

!w::
  HerpData := 0
  VarSetCapacity(HerpData, 666, 0)

  DoQuit := 0
  DoTick := 0
 
  While (0 = DoQuit)
    {
      NumPut(DoTick, HerpData, 4)
      Res := DllCall("Herp.dll\callback", UInt, &HerpData, Cdecl)
     
      if (TYPE_MOUSEMOVE = NumGet(HerpData, 0))
        {
           CoordMode Mouse, Screen
           MouseMove NumGet(HerpData, 8), NumGet(HerpData, 12), 0
        }

      if (TYPE_MOUSEDRAG = NumGet(HerpData, 0))
        {
           CoordMode Mouse, Screen
           MouseClickDrag Left, 0, 0, NumGet(HerpData, 8), NumGet(HerpData, 12), 2, R
        }

      if (TYPE_QUIT = NumGet(HerpData, 0))
        {
           DoQuit := 1
        }

      DoTick := DoTick + 1
    }
return


The DLL part:
[/code]
/* gcc -shared -o Herp.dll Herp.c */
#include <stdlib.h>
#include <stdint.h>
#include <windows.h>

enum HerpTypes
{
  TYPE_MOUSEMOVE = 0,
  TYPE_MOUSEDRAG,
  TYPE_QUIT
};

struct HerpData
{
  int32_t type;
  int32_t tick;
  int32_t out_x;
  int32_t out_y;
} __attribute__((packed));

void callback (struct HerpData *data)
{
  switch (data->tick)
    {
    case 0:
      data->type = TYPE_MOUSEMOVE;
      data->out_x = 200;
      data->out_y = 200;
      break;

    case 1:
      data->type = TYPE_MOUSEDRAG;
      data->out_x = 100;
      data->out_y = 0;
      break;

    case 2:
      data->type = TYPE_QUIT;
      break;
    }
}
[/code]

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List