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

Ask questions about cheating in any games you would like. Does not need to pertain to MicroMacro.
Post Reply
Message
Author
Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

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

#1 Post by Exempt » Fri Oct 29, 2010 12:03 am

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.

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

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

#2 Post by Administrator » Sat Oct 30, 2010 4:17 pm

Try using SendInput and PostMessage. Search on MSDN for documentation and examples.

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

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

#3 Post by Exempt » Sat Oct 30, 2010 6:58 pm

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.

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

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

#4 Post by Administrator » Sat Oct 30, 2010 9:23 pm

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.

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

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

#5 Post by Exempt » Sun Oct 31, 2010 12:47 pm

Thanks for the reply. I'll look into it.

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

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

#6 Post by Exempt » Mon Nov 01, 2010 7:52 pm

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.

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

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

#7 Post by Administrator » Mon Nov 01, 2010 8:32 pm

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.

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

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

#8 Post by Exempt » Tue Nov 02, 2010 1:53 pm

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.

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

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

#9 Post by Administrator » Wed Nov 03, 2010 10:46 am

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.

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

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

#10 Post by Exempt » Wed Nov 03, 2010 7:26 pm

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?

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

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

#11 Post by Administrator » Thu Nov 04, 2010 12:53 am

That is correct.

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

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

#12 Post by Exempt » Thu Nov 04, 2010 2:37 pm

Thanks again.

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

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests