onlinegamehacking@forumn.com


    [Aimbot Practice] Simulate Mouse Click

    Share
    avatar
    Cloud
    ADMIN
    ADMIN

    Posts : 28
    Join date : 2012-10-31

    [Aimbot Practice] Simulate Mouse Click

    Post by Cloud on Thu Feb 28, 2013 2:11 pm

    this code is to move mouse and simulate the mouse click.

    My intension is to place the cursor in the middle of the screen initially and move.

    the code contains approriate comments ,i think that helps to understand code (actually i've seen it in some other forum and made small changes).



    when i run the code the cursor is not placed at the centre of the screen??

    whats wrong with my code?? please somebody correct it??

    here i'm giving my entire code.. (please have patience and go through)

    Code:

    Option Explicit

    ' ----------------------------------------------
    ' * MouseEvent Related Declares *
    ' ----------------------------------------------
    Private Const MOUSEEVENTF_ABSOLUTE = &H8000
    Private Const MOUSEEVENTF_LEFTDOWN = &H2
    Private Const MOUSEEVENTF_LEFTUP = &H4
    Private Const MOUSEEVENTF_MIDDLEDOWN = &H20
    Private Const MOUSEEVENTF_MIDDLEUP = &H40
    Private Const MOUSEEVENTF_MOVE = &H1
    Private Const MOUSEEVENTF_RIGHTDOWN = &H8
    Private Const MOUSEEVENTF_RIGHTUP = &H10

    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, _
    ByVal dx As Long, ByVal dy As Long, ByVal cbuttons As Long, _
    ByVal dwExtraInfo As Long)

    ' ----------------------------------------------
    ' * GetSystemMetrics Related Declares *
    ' ----------------------------------------------
    Private Const SM_CXSCREEN = 0
    Private Const SM_CYSCREEN = 1
    Private Const TWIPS_PER_INCH = 1440
    Private Const POINTS_PER_INCH = 72
    Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex _
    As Long) As Long

    ' ----------------------------------------------
    ' * GetWindowRect Related Declares *
    ' ----------------------------------------------
    Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    End Type
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, _
    lpRect As RECT) As Long


    ' ----------------------------------------------
    ' * Internal Constants and Types *
    ' ----------------------------------------------

    Private Const MOUSE_MICKEYS = 65535

    Public Enum enReportStyle
    rsPixels
    rsTwips
    rsInches
    rsPoints
    End Enum

    Public Enum enButtonToClick
    btcLeft
    btcRight
    btcMiddle
    End Enum


    ' Returns the screen size in pixels or, optionally,
    ' in others scalemode styles
    Public Sub GetScreenRes(ByRef X As Long, ByRef Y As Long, Optional ByVal _
    ReportStyle As enReportStyle)

    X = GetSystemMetrics(SM_CXSCREEN)
    Y = GetSystemMetrics(SM_CYSCREEN)
    If Not IsMissing(ReportStyle) Then
    If ReportStyle <> rsPixels Then
    X = X * Screen.TwipsPerPixelX
    Y = Y * Screen.TwipsPerPixelY
    If ReportStyle = rsInches Or ReportStyle = rsPoints Then
    X = X TWIPS_PER_INCH
    Y = Y TWIPS_PER_INCH
    If ReportStyle = rsPoints Then
    X = X * POINTS_PER_INCH
    Y = Y * POINTS_PER_INCH
    End If
    End If
    End If
    End If
    End Sub


    ' Convert's the mouses coordinate system to
    ' a pixel position.
    Public Function MickeyXToPixel(ByVal mouseX As Long) As Long
    Dim X As Long
    Dim Y As Long
    Dim tX As Single
    Dim tmouseX As Single
    Dim tMickeys As Single

    GetScreenRes X, Y
    tX = X
    tMickeys = MOUSE_MICKEYS
    tmouseX = mouseX

    MickeyXToPixel = CLng(tmouseX / (tMickeys / tX))

    End Function


    ' Converts mouse Y coordinates to pixels
    Public Function MickeyYToPixel(ByVal mouseY As Long) As Long
    Dim X As Long
    Dim Y As Long
    Dim tY As Single
    Dim tmouseY As Single
    Dim tMickeys As Single

    GetScreenRes X, Y
    tY = Y
    tMickeys = MOUSE_MICKEYS
    tmouseY = mouseY

    MickeyYToPixel = CLng(tmouseY / (tMickeys / tY))

    End Function


    ' Converts pixel X coordinates to mickeys
    Public Function PixelXToMickey(ByVal pixX As Long) As Long
    Dim X As Long
    Dim Y As Long
    Dim tX As Single
    Dim tpixX As Single
    Dim tMickeys As Single

    GetScreenRes X, Y
    tMickeys = MOUSE_MICKEYS
    tX = X
    tpixX = pixX

    PixelXToMickey = CLng((tMickeys / tX) * tpixX)

    End Function


    ' Converts pixel Y coordinates to mickeys
    Public Function PixelYToMickey(ByVal pixY As Long) As Long
    Dim X As Long
    Dim Y As Long
    Dim tY As Single
    Dim tpixY As Single
    Dim tMickeys As Single

    GetScreenRes X, Y
    tMickeys = MOUSE_MICKEYS
    tY = Y
    tpixY = pixY

    PixelYToMickey = CLng((tMickeys / tY) * tpixY)

    End Function


    ' The function will center the mouse on a window
    ' or control with an hWnd property. No checking
    ' is done to ensure that the window is not obscured
    ' or not minimized, however it does make sure that
    ' the target is within the boundaries of the
    ' screen.
    Public Function CenterMouseOn(ByVal hwnd As Long) As Boolean
    Dim X As Long
    Dim Y As Long
    Dim maxX As Long
    Dim maxY As Long
    Dim crect As RECT
    Dim rc As Long

    GetScreenRes maxX, maxY
    rc = GetWindowRect(hwnd, crect)

    If rc Then
    X = crect.Left + ((crect.Right - crect.Left) / 2)
    Y = crect.Top + ((crect.Bottom - crect.Top) / 2)
    If (X >= 0 And X <= maxX) And (Y >= 0 And Y <= maxY) Then
    MouseMove X, Y
    CenterMouseOn = True
    Else
    CenterMouseOn = False
    End If
    Else
    CenterMouseOn = False
    End If
    End Function


    ' Simulates a mouse click
    Public Function MouseFullClick(ByVal MBClick As enButtonToClick) As Boolean
    Dim cbuttons As Long
    Dim dwExtraInfo As Long
    Dim mevent As Long

    Select Case MBClick
    Case btcLeft
    mevent = MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP
    Case btcRight
    mevent = MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP
    Case btcMiddle
    mevent = MOUSEEVENTF_MIDDLEDOWN Or MOUSEEVENTF_MIDDLEUP
    Case Else
    MouseFullClick = False
    Exit Function
    End Select
    mouse_event mevent, 0&, 0&, cbuttons, dwExtraInfo
    MouseFullClick = True

    End Function


    Public Sub MouseMove(ByRef xPixel As Long, ByRef yPixel As Long)
    Dim cbuttons As Long
    Dim dwExtraInfo As Long

    mouse_event MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE, _
    PixelXToMickey(xPixel), PixelYToMickey(yPixel), cbuttons, dwExtraInfo

    End Sub

    credits to http://www.bigresource.com

    CAPTURING MOUSE CLICKS - VB.NET
    Code:

    Imports System.Runtime.InteropServices
     
    Public Class UserActivityHook
        Public Delegate Function HookProc(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
     
        Public KeyboardHookProcedure As HookProc
        Public KeyDown As KeyEventHandler
        Public KeyPress As KeyPressEventHandler
        Public KeyUp As KeyEventHandler
     
        Public OnMouseActivity As MouseEventHandler
     
     
        Private Shared hKeyboardHook As Integer
        Private Shared hMouseHook As Integer
        Public MouseHookProcedure As HookProc
        Public Const WH_KEYBOARD_LL As Integer = 13
        Public Const WH_MOUSE_LL As Integer = 14
        Private Const WM_KEYDOWN As Integer = 256
        Private Const WM_KEYUP As Integer = 257
        Private Const WM_LBUTTONDBLCLK As Integer = 515
        Private Const WM_LBUTTONDOWN As Integer = 513
        Private Const WM_LBUTTONUP As Integer = 514
        Private Const WM_MBUTTONDBLCLK As Integer = 521
        Private Const WM_MBUTTONDOWN As Integer = 519
        Private Const WM_MBUTTONUP As Integer = 520
        Private Const WM_MOUSEMOVE As Integer = 512
        Private Const WM_RBUTTONDBLCLK As Integer = 518
        Private Const WM_RBUTTONDOWN As Integer = 516
        Private Const WM_RBUTTONUP As Integer = 517
        Private Const WM_SYSKEYDOWN As Integer = 260
        Private Const WM_SYSKEYUP As Integer = 261
     
    #Region "dll imports"
        ' Methods
        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)> _
        Public Shared Function CallNextHookEx(ByVal idHook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
        End Function
     
        <DllImport("user32")> _
        Public Shared Function GetKeyboardState(ByVal pbKeyState As Byte()) As Integer
        End Function
     
     
     
        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)> _
        Public Shared Function SetWindowsHookEx(ByVal idHook As Integer, ByVal lpfn As HookProc, ByVal hInstance As IntPtr, ByVal threadId As Integer) As Integer
        End Function
     
        <DllImport("user32")> _
        Public Shared Function ToAscii(ByVal uVirtKey As Integer, ByVal uScanCode As Integer, ByVal lpbKeyState As Byte(), ByVal lpwTransKey As Byte(), ByVal fuState As Integer) As Integer
        End Function
     
        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Auto)> _
        Public Shared Function UnhookWindowsHookEx(ByVal idHook As Integer) As Boolean
        End Function
    #End Region
     
    #Region "Structures and whatnot"
        <StructLayout(LayoutKind.Sequential)> _
        Public Class KeyboardHookStruct
            ' Fields
            Public dwExtraInfo As Integer
            Public flags As Integer
            Public scanCode As Integer
            Public time As Integer
            Public vkCode As Integer
        End Class
     
        <StructLayout(LayoutKind.Sequential)> _
        Public Class MouseHookStruct
            ' Fields
            Public dwExtraInfo As Integer
            Public hwnd As Integer
            Public pt As POINT
            Public wHitTestCode As Integer
        End Class
     
        <StructLayout(LayoutKind.Sequential)> _
        Public Class POINT
            ' Fields
            Public x As Integer
            Public y As Integer
        End Class
    #End Region
     
     
     
     
        Public Sub New()
            Start()
        End Sub
     
        Protected Overrides Sub Finalize()
            Try
                Me.Stop()
            Finally
                MyBase.Finalize()
            End Try
        End Sub
     
     
     
     
     
        Public Sub Start()
            If (UserActivityHook.hMouseHook = 0) Then
                Me.MouseHookProcedure = New HookProc(AddressOf Me.MouseHookProc)
                UserActivityHook.hMouseHook = UserActivityHook.SetWindowsHookEx(14, Me.MouseHookProcedure, Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)), 0)
                If (UserActivityHook.hMouseHook = 0) Then
                    Me.Stop()
                    Throw New Exception("SetWindowsHookEx failed.")
                End If
            End If
            If (UserActivityHook.hKeyboardHook = 0) Then
                Me.KeyboardHookProcedure = New HookProc(AddressOf Me.KeyboardHookProc)
                UserActivityHook.hKeyboardHook = UserActivityHook.SetWindowsHookEx(13, Me.KeyboardHookProcedure, Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)), 0)
                If (UserActivityHook.hKeyboardHook = 0) Then
                    Me.Stop()
                    Throw New Exception("SetWindowsHookEx ist failed.")
                End If
            End If
        End Sub
     
        Public Sub [Stop]()
            Dim flag1 As Boolean = True
            Dim flag2 As Boolean = True
            If (UserActivityHook.hMouseHook <> 0) Then
                flag1 = UserActivityHook.UnhookWindowsHookEx(UserActivityHook.hMouseHook)
                UserActivityHook.hMouseHook = 0
            End If
            If (UserActivityHook.hKeyboardHook <> 0) Then
                flag2 = UserActivityHook.UnhookWindowsHookEx(UserActivityHook.hKeyboardHook)
                UserActivityHook.hKeyboardHook = 0
            End If
            If (Not flag1 OrElse Not flag2) Then
                Throw New Exception("UnhookWindowsHookEx failed.")
            End If
        End Sub
     
     
        Private Function MouseHookProc(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
            If ((nCode >= 0) AndAlso (Not Me.OnMouseActivity Is Nothing)) Then
                Dim buttons1 As MouseButtons = MouseButtons.None
                Dim num3 As Integer = wParam
                If (num3 <> 513) Then
                    If (num3 = 516) Then
                        buttons1 = MouseButtons.Right
                    End If
                Else
                    buttons1 = MouseButtons.Left
                End If
                Dim num1 As Integer = 0
                If (buttons1 <> MouseButtons.None) Then
                    If ((wParam = 515) OrElse (wParam = 518)) Then
                        num1 = 2
                    Else
                        num1 = 1
                    End If
                End If
                Dim struct1 As MouseHookStruct = CType(Marshal.PtrToStructure(lParam, GetType(MouseHookStruct)), MouseHookStruct)
                Dim args1 As New MouseEventArgs(buttons1, num1, struct1.pt.x, struct1.pt.y, 0)
                Me.OnMouseActivity.Invoke(Me, args1)
            End If
            Return UserActivityHook.CallNextHookEx(UserActivityHook.hMouseHook, nCode, wParam, lParam)
        End Function
     
     
        Private Function KeyboardHookProc(ByVal nCode As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As Integer
            If ((nCode >= 0) AndAlso (((Not Me.KeyDown Is Nothing) OrElse (Not Me.KeyUp Is Nothing)) OrElse (Not Me.KeyPress Is Nothing))) Then
                Dim struct1 As KeyboardHookStruct = CType(Marshal.PtrToStructure(lParam, GetType(KeyboardHookStruct)), KeyboardHookStruct)
                If ((Not Me.KeyDown Is Nothing) AndAlso ((wParam = 256) OrElse (wParam = 260))) Then
                    Dim args1 As New KeyEventArgs(CType(struct1.vkCode, Keys))
                    Me.KeyDown.Invoke(Me, args1)
                End If
                If ((Not Me.KeyPress Is Nothing) AndAlso (wParam = 256)) Then
                    Dim buffer1 As Byte() = New Byte(256 - 1) {}
                    UserActivityHook.GetKeyboardState(buffer1)
                    Dim buffer2 As Byte() = New Byte(2 - 1) {}
                    If (UserActivityHook.ToAscii(struct1.vkCode, struct1.scanCode, buffer1, buffer2, struct1.flags) = 1) Then
                        Dim args2 As New KeyPressEventArgs(Convert.ToChar(buffer2(0)))
                        Me.KeyPress.Invoke(Me, args2)
                    End If
                End If
                If ((Not Me.KeyUp Is Nothing) AndAlso ((wParam = 257) OrElse (wParam = 261))) Then
                    Dim args3 As New KeyEventArgs(CType(struct1.vkCode, Keys))
                    Me.KeyUp.Invoke(Me, args3)
                End If
            End If
            Return UserActivityHook.CallNextHookEx(UserActivityHook.hKeyboardHook, nCode, wParam, lParam)
        End Function
     
    End Class



    <signature>

      Current date/time is Mon Nov 20, 2017 9:14 am