Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Emulate mouse click?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Fri Apr 19, 2013 4:06 am    Post subject: Emulate mouse click? Reply with quote

So it shows up in Spy++.
I'v tried mouse_event, PostMessage, SendMessage
My last try was CallWindowProc

Im using Solitaire as my test platform but the game i wish to do it for is a directx game which seems to be eating the messages when in fullscreen only. In windowed mode it works.

In solitaire i get this when i click


Im doing this in C# btw. The code works fine in solitaire but doesnt show in Spy++.
It clicks every 5 seconds after i stop moving my mouse.
Heres the code, i use a special injector i made to inject managed dlls.
Code:
        #region API

        [DllImport("user32", EntryPoint = "GetWindowLong")]
        static extern IntPtr GetWindowLong(IntPtr hWnd, GWL nIndex);

        [DllImport("user32", EntryPoint = "GetWindowLongPtr")]
        static extern IntPtr GetWindowLongPtr(IntPtr hWnd, GWL nIndex);

        [DllImport("user32")]
        static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, WM Msg, int wParam, int lParam);

        #endregion

        #region enum
        public enum GWL
        {
            GWL_WNDPROC = -4,
            GWL_HINSTANCE = -6,
            GWL_HWNDPARENT = -8,
            GWL_STYLE = -16,
            GWL_EXSTYLE = -20,
            GWL_USERDATA = -21,
            GWL_ID = -12
        }
        public enum WM
        {
            WM_MOUSEFIRST = 0x200,
            WM_MOUSEMOVE = 0x200,
            WM_LBUTTONDOWN = 0x201,
            WM_LBUTTONUP = 0x202,
            WM_LBUTTONDBLCLK = 0x203,
            WM_RBUTTONDOWN = 0x204,
            WM_RBUTTONUP = 0x205,
            WM_RBUTTONDBLCLK = 0x206,
            WM_MBUTTONDOWN = 0x207,
            WM_MBUTTONUP = 0x208,
            WM_MBUTTONDBLCLK = 0x209,
            WM_MOUSEWHEEL = 0x20A,
            WM_MOUSEHWHEEL = 0x20E
        }
        #endregion

        public static int DllMain(string arg)
        {
            new Thread(Derp).Start();
            return 0;
        }

        static void Derp()
        {
            Point Current = Cursor.Position;
            IntPtr hWnd = Process.GetCurrentProcess().MainWindowHandle;
            IntPtr GWL_ = IntPtr.Size == 4 ? GetWindowLong(hWnd, GWL.GWL_WNDPROC) : GetWindowLongPtr(hWnd, GWL.GWL_WNDPROC);
            if (GWL_ == IntPtr.Zero)
            {
                throw new Exception("Could not GetWindowLong");
            }
            while (true)
            {
                Thread.Sleep(5000);
                if (Cursor.Position == Current)
                {
                    CallWindowProc(GWL_, hWnd, WM.WM_LBUTTONDOWN, 0, 0);
                    CallWindowProc(GWL_, hWnd, WM.WM_LBUTTONUP, 0, 0);
                }
                else Current = Cursor.Position;
            }
        }


Any idea why these messages wont show up in Spy++.
I know these arnt real mouse clicks, but there must be a way to trick it into thinking it is a real click.

_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Sat Apr 20, 2013 6:14 pm    Post subject: Reply with quote

Hook DirectInput and inject the mouse data into GetDeviceState / GetDeviceData.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Sun Apr 21, 2013 11:42 am    Post subject: Reply with quote

I will try that. I did however manage to simulate exactly what spy++ was giving me but it still failed. worked fine on another game though.

I'm thinking the game has it's own hook to determine if the key was real or not. I'm not the only person having this issue.
Apparently all methods of simulating keys has been patched.
But i'm gonna try everything i can think of.

I might try finding it if i fail at everything else.

_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Mon Apr 22, 2013 12:14 am    Post subject: This post has 1 review(s) Reply with quote

When you send keys from another application like that, there is a bit set in the keyboard data saying that the key was injected. If they are using a low level keyboard hook to read the data to validate it, they can check for that key being faked.

You could try hooking SetWindowsHook / SetWindowsHookEx to block them from being allowed to call it to stop their keyboard hook (if any) from working.

With SetWindowsHookEx, the id will be WH_KEYBOARD/WH_KEYBOARD_LL.

If they use WH_KEYBOARD_LL, the callback proc will have a keyboard data struct passed to it when its called. The 'flags' member of the structure will have the bit 'LLKHF_INJECTED' set if its an injected key.

There are a handful other methods they can be using to block the key presses though.

Heres an article from a while ago covering how to get around it:
http://pastebin.com/rj4YcW4C

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Mon Apr 22, 2013 1:44 am    Post subject: Reply with quote

This believe this is exactly what im after. Gonna go read this now.

I had SetWindowsHook on my list to try.
I'm gonna try this first.
Thanks Wiccaan

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites