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 


[C#] Mouse Hook!

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

Joined: 04 May 2007
Posts: 957
Location: Why do you care?

PostPosted: Tue Feb 05, 2008 6:48 pm    Post subject: [C#] Mouse Hook! Reply with quote

Ok, I'm going to get straight to the point, because I have things that I need to do (*cough*homework*cough*)

Now, this is going to show you how to modify my keyboard hook that I posted before to support mouse clicks as well.

First, we need to go ahead and declare the unmanaged structs:

Code:

        [StructLayout(LayoutKind.Sequential)]
        private struct POINT
        {
            public int x;
            public int y;
        }

        [StructLayout(LayoutKind.Sequential)]
        private struct MSLLHOOKSTRUCT
        {
            public POINT pt;
            public uint mouseData;
            public uint flags;
            public uint time;
            public IntPtr dwExtraInfo;
        }


Then, let's go ahead and declare our WM enum, with the Mouse messages:

Code:

        public enum WM
        {
            WM_LBUTTONDOWN  = 0x0201,
            WM_LBUTTONUP    = 0x0202,
            WM_MOUSEMOVE    = 0x0200,
            WM_MOUSEWHEEL   = 0x020A,
            WM_RBUTTONDOWN  = 0x0204,
            WM_RBUTTONUP    = 0x0205
        }


Next, we need to modify our KeyHandler (I'll be using the one without customizable hotkeys, just for simplicity's sake--do note that it is possible to create something like that, and it wouldn't be very hard, you just have to use your brain Razz .):

Code:

public static void KeyHandler(IntPtr wParam, IntPtr lParam)
{
      int key = Marshal.ReadInt32(lParam);

      Hook.VK vk = (Hook.VK)key;

      if (vk == null) //it's a mouse option
      {
          DoMouse(wParam, lParam);
          return;
      }

       switch(vk)
       {
            case Hook.VK.F5: MessageBox.Show("You pressed F5!");
                              break;

            case Hook.VK.F6: MessageBox.Show("You pressed F6!");
                              break;

             //etc...

             default: break;
       }
}


And let's create our mouse handler

Code:

public static void DoMouse(IntPtr wParam, IntPtr lParam)
{
      Hook.WM wm = (Hook.WM)wParam;
     
      if (wm == null) return;

      //get our structure

      Hook.MSLLHOOKSTRUCT mouse_params = (Hook.MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Hook.MSLLHOOKSTRUCT));

      LblX.Text = mouse_params.pt.X;
      LblY.Text = mouse_params.pt.Y;
}


~~

Hope I've helped someone.

CREDITS

This was highly influenced by this
article--meaning that I DID NOT WRITE MOST OF THIS CODE, I SIMPLY BROUGHT IT HERE FOR OTHERS TO USE.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1888
Location: Canada

PostPosted: Tue Feb 05, 2008 7:22 pm    Post subject: Reply with quote

I would like to point out that not everything you write should end up in this section. Something short and too the point such as this is better of in the normal programming section. Wink
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 957
Location: Why do you care?

PostPosted: Tue Feb 05, 2008 8:19 pm    Post subject: Reply with quote

=P

It may be short and to the point, but it could quite possibly help someone. It follows the same ideas as the keyboard hook, but okey.

I'll keep that in mind. =p

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
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 -> 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