Page 1 of 1

Trying to simulate a mouse click in a game that uses DI

Posted: Fri Oct 29, 2010 12:03 am
by Exempt
I'm trying to simulate a mouse click in a game that uses Direct Input. I really don't want to make a hook or anything like that at this point but I do need to make this click only affect the game window.

Thanks for any advice.

Edit: Forgot to add I'm using c++ to do this.

Re: Trying to simulate a mouse click in a game that uses DI

Posted: Sat Oct 30, 2010 4:17 pm
by Administrator
Try using SendInput and PostMessage. Search on MSDN for documentation and examples.

Re: Trying to simulate a mouse click in a game that uses DI

Posted: Sat Oct 30, 2010 6:58 pm
by Exempt
Sadly them don't really work. SendInput can work with direct input apps using the direct input scan codes but it's global and i cannot use it with an inactive window.

I really need a way to send mouse input into the inactive game window.

Re: Trying to simulate a mouse click in a game that uses DI

Posted: Sat Oct 30, 2010 9:23 pm
by Administrator
Unfortunately, the only decent way to do that would be to make use of hooks.

The easy way to do it would be to get a D3D hook starter kit (search for this on www.gamedeception.net). You'll have 99% of the work done for you there; just need to modify the hook for the mouse and/or call the original in your own code.

Re: Trying to simulate a mouse click in a game that uses DI

Posted: Sun Oct 31, 2010 12:47 pm
by Exempt
Thanks for the reply. I'll look into it.

Re: Trying to simulate a mouse click in a game that uses DI

Posted: Mon Nov 01, 2010 7:52 pm
by Exempt
I wish there was a tutorial that ddn't have so much in it already. I'm still very new to this and need something to start with not a full working hack pushed in my face. :? I'm gonna try to dig around more but if you happen to stumble across something thats a very plain dinput mouse hook, please send it my way.

Re: Trying to simulate a mouse click in a game that uses DI

Posted: Mon Nov 01, 2010 8:32 pm
by Administrator
The starter kit I mentioned just provides working hooks to all the functions which you need to fill in yourself. Trust me, you don't want to do all that work yourself. Even though you think you might only need one or two functions, you would still have to hook every function for DirectX because it is object oriented, unlike OpenGL. It's not worth the time.

Re: Trying to simulate a mouse click in a game that uses DI

Posted: Tue Nov 02, 2010 1:53 pm
by Exempt
I'll try to figure it out but I think for my first c++ hack I may have to settle for a bit less. How do you go about sending mouse input to active windows? I can sends keyboard events and stuff but haven't got the mouse input part yet.

Edit: mouseLClick(); This sends input to the game just fine.

Re: Trying to simulate a mouse click in a game that uses DI

Posted: Wed Nov 03, 2010 10:46 am
by Administrator
This is how it's done in MicroMacro

Code: Select all

void MouseDevice::leftHold(unsigned int modifier)
{
    if( attachedHwnd ) {
        LPARAM lparam = MAKELPARAM(vMouseX, vMouseY);
        PostMessage(attachedHwnd, WM_LBUTTONDOWN, MK_LBUTTON, lparam);
    } else {
        INPUT inp;
        memset(&inp, 0, sizeof(INPUT));
        inp.type = INPUT_MOUSE;
        inp.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
        SendInput(1, &inp, sizeof(INPUT));
    }
}

void MouseDevice::leftRelease(unsigned int modifier)
{
    if( attachedHwnd ) {
        LPARAM lparam = MAKELPARAM(vMouseX, vMouseY);
        PostMessage(attachedHwnd, WM_LBUTTONUP, MK_LBUTTON, lparam);
    } else {
        INPUT inp;
        memset(&inp, 0, sizeof(INPUT));
        inp.type = INPUT_MOUSE;
        inp.mi.dwFlags = MOUSEEVENTF_LEFTUP;
        SendInput(1, &inp, sizeof(INPUT));
    }
}

void MouseDevice::leftClick(unsigned int modifier)
{
    leftHold(modifier);
    Sleep(delay);
    leftRelease(modifier);
}
Since you're not using attached input, just use the SendInput information.

Re: Trying to simulate a mouse click in a game that uses DI

Posted: Wed Nov 03, 2010 7:26 pm
by Exempt
Thanks a bunch, That replains why my keyboard wasn't working 100% too... -.- Release the keys!

Attached input would be where it sends the input directly to a window i guess?

Re: Trying to simulate a mouse click in a game that uses DI

Posted: Thu Nov 04, 2010 12:53 am
by Administrator
That is correct.

Re: Trying to simulate a mouse click in a game that uses DI

Posted: Thu Nov 04, 2010 2:37 pm
by Exempt
Thanks again.

I've got most of the base functions done now for reading and writing memory and for my keyoard and mouse. :D