No Recoil

Posts 1–11 of 11 · Page 1 of 1
No Recoil
A while back, i thought about a no recoil hack with vb. I tried multiple things, but they all didn't work out, so i gave up.
I didn't ask you guys for help, and since most of you (especially Jason) i had to ask you guys aswell.

I want to set the Mouse Position to Intx, Inty + 20

Intx = Me.Screen.Resolution.Width /2
Inty = Me.Screen.Resolution.Height /2

Or atleast something like that, i already have my codes.

But how to get that, when lbutton is clicked?
I tried with Getasynckeystate (VK_Lbutton)
VK_Lbutton = &h1 or something, it worked for my crosshairs...
but if i click, it stays @ the middle of the screen, and i only want it to go there when click (hold)

Any suggestions??

Thanks!
Okay personally I'd set up a thread to watch for the LButton being held down.

[highlight=vb.net]
Private Sub MouseMonitor()
Dim centerScreen As New Point(Screen.PrimaryScreen.Bounds.Width \ 2, Screen.PrimaryScreen.Bounds.Height \ 2)
Do
If GetAsyncKeyState(Keys.LButton) And &H8000 Then
Threading.Thread.Sleep(200) 'give some time to let the user release if it's just a mouseclick
While GetAsyncKeyState(Keys.LButton) And &H8000
Cursor.Position = centerScreen
End While
End If
Threading.Thread.Sleep(100) 'so we dont call GAKS too often and drain system resources.
Loop 'infinite
End Sub
[/highlight]

To run that you'll have to create a thread for it:
[highlight=vb.net]
Dim mouseThread As New Threading.Thread(AddressOf MouseMonitor)
mouseThread.Priority = Threading.ThreadPriority.BelowNormal
mouseThread.Start()
[/highlight]


Let me know how it goes
Excuse any syntax errors, I couldn't be bothered opening an IDE. Haven't tested it but it seems it should work
Thanks! im gonna try it , again...


edit:
@Jason Your code works perfect, however, its not what i want.
Can't i set the MOUSE position instead of the cursor? i searched for it, but i can't find how to. This doesn't work in game with aiming, atleast not with WR....

@Blubb1337 maybey u can help meh?
[highlight=vb.net]
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function SetCursorPos(ByVal X As Integer, ByVal Y As Integer) As Boolean
End Function
[/highlight]

Change
Code:
Cursor.Position = centerScreen
to
Code:
SetCursorPos(centerScreen.X, centerScreen.Y)
SendInput Function (Windows)

I quickly created this code, hope there are no mistakes. Thanks to pinvoke.net for the declarations.
[highlight=vb.net]Imports System.Runtime.InteropServices

<DllImport("user32.dll")> _
Private Shared Function SendInput(ByVal cInputs As Integer, ByRef pInputs As INPUT, ByVal cbSize As Integer) As Integer
End Function

<StructLayout(LayoutKind.Explicit)> _
Private Structure INPUT
<FieldOffset(0)> Dim dwType As Integer
<FieldOffset(4)> Dim mouseInput As mouseInput
<FieldOffset(4)> Dim keyboardInput As KEYBDINPUT
<FieldOffset(4)> Dim hardwareInput As hardwareInput
End Structure

<StructLayout(LayoutKind.Explicit)> _
Private Structure KEYBDINPUT
<FieldOffset(0)> Public wVk As Short
<FieldOffset(2)> Public wScan As Short
<FieldOffset(4)> Public dwFlags As Integer
<FieldOffset(8)> Public time As Integer
<FieldOffset(12)> Public dwExtraInfo As IntPtr
End Structure

<StructLayout(LayoutKind.Explicit)> _
Private Structure HARDWAREINPUT
<FieldOffset(0)> Public uMsg As Integer
<FieldOffset(4)> Public wParamL As Short
<FieldOffset(6)> Public wParamH As Short
End Structure

<StructLayout(LayoutKind.Explicit)> _
Private Structure MOUSEINPUT
<FieldOffset(0)> Public dx As Integer
<FieldOffset(4)> Public dy As Integer
<FieldOffset(8)> Public mouseData As Integer
<FieldOffset(12)> Public dwFlags As Integer
<FieldOffset(16)> Public time As Integer
<FieldOffset(20)> Public dwExtraInfo As IntPtr
End Structure

Private Const INPUT_MOUSE As UInt32 = 0
Private Const MOUSEEVENTF_MOVE As UInt32 = &H1
Private Const MOUSEEVENTF_ABSOLUTE As UInt32 = &H8000

Private Function MoveMouse(ByVal X As Integer, ByVal Y As Integer) As Boolean
Dim inp As New INPUT
Dim mi As New MOUSEINPUT
inp.dwType = INPUT_MOUSE
inp.mouseInput = mi
inp.mouseInput.dx = X * (65535 \ Screen.PrimaryScreen.Bounds.Width)
inp.mouseInput.dy = Y * (65535 \ Screen.PrimaryScreen.Bounds.Height)
inp.mouseInput.time = 0
inp.mouseInput.dwFlags = MOUSEEVENTF_MOVE or MOUSEEVENTF_ABSOLUTE
Return SendInput(1, inp, Marshal.SizeOf(new INPUT)) <> 0
End Function[/highlight]

Usage:
MoveMouse(centerScreen.X, centerScreen.Y)

EDIT - Seems like Jason bet me to it. If SetCursorPos doesn't work, try this instead.
Tried Jason's code, first i thought the dll import was wrong, but i forgot:
Imports System.Runtime.InteropServices
Imports System.Text

Code worked perfect, except it still didn't change the crosshair, and it made the game all laggy and shit. Now trying masters code.

edit: Tried his code, doesn't work at all, with Masters codes added, my code is now:

Code:
Imports System.Runtime.InteropServices
Imports System.Text

Public Class Form1

    <DllImport("user32.dll")> _
    Private Shared Function SendInput(ByVal cInputs As Integer, ByRef pInputs As INPUT, ByVal cbSize As Integer) As Integer
    End Function

    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Int32) As Int16
    Private Gamelist As New List(Of Game)
    <StructLayout(LayoutKind.Explicit)> _
    Private Structure INPUT
        <FieldOffset(0)> Dim dwType As Integer
        <FieldOffset(4)> Dim mouseInput As mouseInput
        <FieldOffset(4)> Dim keyboardInput As KEYBDINPUT
        <FieldOffset(4)> Dim hardwareInput As hardwareInput
    End Structure

    <StructLayout(LayoutKind.Explicit)> _
Private Structure KEYBDINPUT
        <FieldOffset(0)> Public wVk As Short
        <FieldOffset(2)> Public wScan As Short
        <FieldOffset(4)> Public dwFlags As Integer
        <FieldOffset(8)> Public time As Integer
        <FieldOffset(12)> Public dwExtraInfo As IntPtr
    End Structure

    <StructLayout(LayoutKind.Explicit)> _
Private Structure HARDWAREINPUT
        <FieldOffset(0)> Public uMsg As Integer
        <FieldOffset(4)> Public wParamL As Short
        <FieldOffset(6)> Public wParamH As Short
    End Structure

    <StructLayout(LayoutKind.Explicit)> _
Private Structure MOUSEINPUT
        <FieldOffset(0)> Public dx As Integer
        <FieldOffset(4)> Public dy As Integer
        <FieldOffset(8)> Public mouseData As Integer
        <FieldOffset(12)> Public dwFlags As Integer
        <FieldOffset(16)> Public time As Integer
        <FieldOffset(20)> Public dwExtraInfo As IntPtr
    End Structure

    Private Const INPUT_MOUSE As UInt32 = 0
    Private Const MOUSEEVENTF_MOVE As UInt32 = &H1
    Private Const MOUSEEVENTF_ABSOLUTE As UInt32 = &H8000
    Private Structure Game
        Dim Name As String
        Dim ProcessName As String
        Dim Shortcut As String
    End Structure

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Application.Exit()
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Gamelist.Add(New Game With {.Name = "Warrock", .ProcessName = "warrock", .Shortcut = "WR"})
        Gamelist.Add(New Game With {.Name = "Gunz", .ProcessName = "gunz", .Shortcut = "GZ"})
        Gamelist.Add(New Game With {.Name = "Combat Arms", .ProcessName = "engine", .Shortcut = "CA"})
        Gamelist.Add(New Game With {.Name = "Crossfire", .ProcessName = "crossfire", .Shortcut = "CF"})
        Gamelist.Add(New Game With {.Name = "Project Blackout", .ProcessName = "pblackout", .Shortcut = "PB"})
        Gamelist.Add(New Game With {.Name = "Modern Warfare", .ProcessName = "iw3mp", .Shortcut = "M1"})
        Gamelist.Add(New Game With {.Name = "Modern Warfare 2", .ProcessName = "iw4mp", .Shortcut = "M2"})
        Gamelist.Add(New Game With {.Name = "Black Ops", .ProcessName = "blackopsmp", .Shortcut = "BO"})
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        For i = 0 To Gamelist.Count - 1
            With Gamelist(i)
                Dim p() As Process = Process.GetProcessesByName(.ProcessName)
                If p.Count <> 0 Then
                    TextBox1.Text = .Shortcut
                    Timer2.Start()
                    Timer1.Stop()
                    Return
                End If
            End With
        Next

        TextBox1.Text = ""
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If TextBox1.Text <> "" Then
            For i = 0 To Gamelist.Count - 1
                With Gamelist(i)
                    If .Shortcut = TextBox1.Text Then
                        Me.Label1.Text = String.Format("Currently: In-Game: {0}    {1}", .Name, IIf(TextBox2.Text.ToLower = "date", String.Concat("(", TimeString, ")"), ""))
                        Me.Label1.ForeColor = Color.LimeGreen
                        Me.ForeColor = Color.LimeGreen
                        Timer3.Start()
                    End If
                End With
            Next
            Timer1.Start()
        Else
            Me.Label1.Text = String.Format("Currently: Not in-game      {0}", IIf(TextBox2.Text.ToLower = "date", String.Concat("(", TimeString, ")"), ""))
            Me.Label1.ForeColor = Color.Red
            Me.ForeColor = Color.Red
            Timer1.Start()
            TextBox2.Text = "Date"
            Timer3.Stop()
            Dim mouseThread As New Threading.Thread(AddressOf MouseMonitor)
            mouseThread.Priority = Threading.ThreadPriority.BelowNormal
            mouseThread.Abort()
        End If
    End Sub

    Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        If TextBox1.Text = "" Then
            Timer3.Stop()
        Else
            Dim mouseThread As New Threading.Thread(AddressOf MouseMonitor)
            mouseThread.Priority = Threading.ThreadPriority.BelowNormal
            mouseThread.Start()
        End If
    End Sub
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Sub MouseMonitor()
        Do
            If GetAsyncKeyState(Keys.LButton) And &H8000 Then
                Threading.Thread.Sleep(200) 'give some time to let the user release if its just a mouseclick
                While GetAsyncKeyState(Keys.LButton) And &H8000
                    MoveMouse(Screen.PrimaryScreen.Bounds.Width \ 2, Screen.PrimaryScreen.Bounds.Height \ 2)
                End While
            End If
            Threading.Thread.Sleep(100) 'so we dont call GAKS too often and drain system resources.
        Loop 'infinite
    End Sub

    Private Function MoveMouse(ByVal X As Integer, ByVal Y As Integer) As Boolean
        Dim inp As New INPUT
        Dim mi As New MOUSEINPUT
        inp.dwType = INPUT_MOUSE
        inp.mouseInput = mi
        inp.mouseInput.dx = X * (65535 \ Screen.PrimaryScreen.Bounds.Width)
        inp.mouseInput.dy = Y * (65535 \ Screen.PrimaryScreen.Bounds.Height)
        inp.mouseInput.time = 0
        inp.mouseInput.dwFlags = MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE
        Return SendInput(1, inp, Marshal.SizeOf(New INPUT)) <> 0
    End Function


End Class
I tested the MouseMonitor function from your code and it worked fine. It did what it was supposed to do (which was keep the mouse in the center of the screen).

Also, I made a mistake on the MoveMouse function (I put .Width instead of .Height) but it seems like you already fixed it.
Yeah i already fixed it, but your code doesn't seem to work, and jason's code does, but not in-game. Jason's makes me lagg when i shoot aswell, so it laggs, and it doesn't work in-game. Your's didn't even work with my mouse, so i didn't try it in-game, should i?
Wait, why does your code start a thread and then Abort it straight away?

[highlight=vb.net]Dim mouseThread As New Threading.Thread(AddressOf MouseMonitor)
mouseThread.Priority = Threading.ThreadPriority.BelowNormal
mouseThread.Abort()[/highlight]
Remove the code, it's redundant.

Also, you added this code in a timer:
[highlight=vb.net]Dim mouseThread As New Threading.Thread(AddressOf MouseMonitor)
mouseThread.Priority = Threading.ThreadPriority.BelowNormal
mouseThread.Start()[/highlight]

Wouldn't that mean that the MouseMonitor will pile on top of each other infinitely? That's why it probably lags. Take the code out of the timer and put it in the Form_Load event. Put a check in the Do ... Loop to see if TextBox1.Text is empty. Something like this:
[highlight=vb.net] Private Sub MouseMonitor()
Do
If Not String.IsNullOrEmpty(TextBox1.Text) AndAlso GetAsyncKeyState(Keys.LButton) And &H8000 Then
Threading.Thread.Sleep(200) 'give some time to let the user release if its just a mouseclick
While GetAsyncKeyState(Keys.LButton) And &H8000
MoveMouse(Screen.PrimaryScreen.Bounds.Width \ 2, Screen.PrimaryScreen.Bounds.Height \ 2)
End While
End If
Threading.Thread.Sleep(100) 'so we dont call GAKS too often and drain system resources.
Loop 'infinite
End Sub[/highlight]


Make sure to also add this to the Form_Load event code:
[highlight=vb.net]Control.CheckForIllegalCrossThreads = False[/highlight]
im gonna try, its:
Code:
Control.CheckForIllegalCrossThreadCalls = False
tho.

but if i can't abort it, it wont stop, untill its closed. I have to abort it, as soon as you close the game...
So i HAVE to add it in a timer right?

My Code now:
Code:
Imports System.Runtime.InteropServices
Imports System.Text

Public Class Form1

    <DllImport("user32.dll")> _
    Private Shared Function SendInput(ByVal cInputs As Integer, ByRef pInputs As INPUT, ByVal cbSize As Integer) As Integer
    End Function

    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Int32) As Int16
    Private Gamelist As New List(Of Game)
    <StructLayout(LayoutKind.Explicit)> _
    Private Structure INPUT
        <FieldOffset(0)> Dim dwType As Integer
        <FieldOffset(4)> Dim mouseInput As mouseInput
        <FieldOffset(4)> Dim keyboardInput As KEYBDINPUT
        <FieldOffset(4)> Dim hardwareInput As hardwareInput
    End Structure

    <StructLayout(LayoutKind.Explicit)> _
Private Structure KEYBDINPUT
        <FieldOffset(0)> Public wVk As Short
        <FieldOffset(2)> Public wScan As Short
        <FieldOffset(4)> Public dwFlags As Integer
        <FieldOffset(8)> Public time As Integer
        <FieldOffset(12)> Public dwExtraInfo As IntPtr
    End Structure

    <StructLayout(LayoutKind.Explicit)> _
Private Structure HARDWAREINPUT
        <FieldOffset(0)> Public uMsg As Integer
        <FieldOffset(4)> Public wParamL As Short
        <FieldOffset(6)> Public wParamH As Short
    End Structure

    <StructLayout(LayoutKind.Explicit)> _
Private Structure MOUSEINPUT
        <FieldOffset(0)> Public dx As Integer
        <FieldOffset(4)> Public dy As Integer
        <FieldOffset(8)> Public mouseData As Integer
        <FieldOffset(12)> Public dwFlags As Integer
        <FieldOffset(16)> Public time As Integer
        <FieldOffset(20)> Public dwExtraInfo As IntPtr
    End Structure

    Private Const INPUT_MOUSE As UInt32 = 0
    Private Const MOUSEEVENTF_MOVE As UInt32 = &H1
    Private Const MOUSEEVENTF_ABSOLUTE As UInt32 = &H8000
    Private Structure Game
        Dim Name As String
        Dim ProcessName As String
        Dim Shortcut As String
    End Structure

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Application.Exit()
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Control.CheckForIllegalCrossThreadCalls = False
        Gamelist.Add(New Game With {.Name = "Warrock", .ProcessName = "warrock", .Shortcut = "WR"})
        Gamelist.Add(New Game With {.Name = "Gunz", .ProcessName = "gunz", .Shortcut = "GZ"})
        Gamelist.Add(New Game With {.Name = "Combat Arms", .ProcessName = "engine", .Shortcut = "CA"})
        Gamelist.Add(New Game With {.Name = "Crossfire", .ProcessName = "crossfire", .Shortcut = "CF"})
        Gamelist.Add(New Game With {.Name = "Project Blackout", .ProcessName = "pblackout", .Shortcut = "PB"})
        Gamelist.Add(New Game With {.Name = "Modern Warfare", .ProcessName = "iw3mp", .Shortcut = "M1"})
        Gamelist.Add(New Game With {.Name = "Modern Warfare 2", .ProcessName = "iw4mp", .Shortcut = "M2"})
        Gamelist.Add(New Game With {.Name = "Black Ops", .ProcessName = "blackopsmp", .Shortcut = "BO"})
        If TextBox3.Text = "Start" Then
            Dim mouseThread As New Threading.Thread(AddressOf MouseMonitor)
            mouseThread.Priority = Threading.ThreadPriority.BelowNormal
            mouseThread.Start()
        End If
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        For i = 0 To Gamelist.Count - 1
            With Gamelist(i)
                Dim p() As Process = Process.GetProcessesByName(.ProcessName)
                If p.Count <> 0 Then
                    TextBox1.Text = .Shortcut
                    Timer2.Start()
                    Timer1.Stop()
                    Return
                End If
            End With
        Next

        TextBox1.Text = ""
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If TextBox1.Text <> "" Then
            For i = 0 To Gamelist.Count - 1
                With Gamelist(i)
                    If .Shortcut = TextBox1.Text Then
                        Me.Label1.Text = String.Format("Currently: In-Game: {0}    {1}", .Name, IIf(TextBox2.Text.ToLower = "date", String.Concat("(", TimeString, ")"), ""))
                        Me.Label1.ForeColor = Color.LimeGreen
                        Me.ForeColor = Color.LimeGreen
                        TextBox3.Text = "Start"
                    End If
                End With
            Next
            Timer1.Start()
        Else
            Me.Label1.Text = String.Format("Currently: Not in-game      {0}", IIf(TextBox2.Text.ToLower = "date", String.Concat("(", TimeString, ")"), ""))
            Me.Label1.ForeColor = Color.Red
            Me.ForeColor = Color.Red
            Timer1.Start()
            TextBox2.Text = "Date"
            TextBox3.Text = "Stop"
        End If
    End Sub

    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Sub MouseMonitor()
        Do
            If Not String.IsNullOrEmpty(TextBox1.Text) AndAlso GetAsyncKeyState(Keys.LButton) And &H8000 Then
                Threading.Thread.Sleep(200) 'give some time to let the user release if its just a mouseclick
                While GetAsyncKeyState(Keys.LButton) And &H8000
                    MoveMouse(Screen.PrimaryScreen.Bounds.Width \ 2, Screen.PrimaryScreen.Bounds.Height \ 2)
                End While
            End If
            Threading.Thread.Sleep(100) 'so we dont call GAKS too often and drain system resources.
        Loop 'infinite
    End Sub

    Private Function MoveMouse(ByVal X As Integer, ByVal Y As Integer) As Boolean
        Dim inp As New INPUT
        Dim mi As New MOUSEINPUT
        inp.dwType = INPUT_MOUSE
        inp.mouseInput = mi
        inp.mouseInput.dx = X * (65535 \ Screen.PrimaryScreen.Bounds.Width)
        inp.mouseInput.dy = Y * (65535 \ Screen.PrimaryScreen.Bounds.Height)
        inp.mouseInput.time = 0
        inp.mouseInput.dwFlags = MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE
        Return SendInput(1, inp, Marshal.SizeOf(New INPUT)) <> 0
    End Function


End Class
Sorry for late reply, i know how annoying it is, when people ask your help, and don't reply.
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us