VB - Advanced Key Bot

  • Thread starter Thread starter VaecorsDraconem
  • Start date Start date
V

VaecorsDraconem

Guest
My code is as follows:

Public Class Form1
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Byte
Public Const KEYEVENTF_EXTENDEDKEY = &H1 Key DOWN
Public Const KEYEVENTF_KEYUP = &H2 Key UP
Dim En As Integer
Dim Time As Integer
Private Sub ShiftDwn()
keybd_event(Keys.LShiftKey, MapVirtualKey(Keys.LShiftKey, 0), 0, 0) LSHIFT Key DOWN
keybd_event(Keys.LShiftKey, MapVirtualKey(Keys.LShiftKey, 0), KEYEVENTF_EXTENDEDKEY Or 0, 0)
End Sub

Private Sub ShiftUp()
keybd_event(Keys.LShiftKey, MapVirtualKey(Keys.LShiftKey, 0), KEYEVENTF_KEYUP, 0)
End Sub


Now in your procedure

ShiftDwn

Do what you want with holding shift key


ShiftUp
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
En = 0
Time = 0

End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode

Case Keys.Z
Timer1.Enabled = True
Case Keys.X
Timer1.Enabled = False


End Select
End Sub

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
SendKeys.Send("{q}")
ShiftDwn()
Timer2.Enabled = True
Timer1.Enabled = False
End Sub

Private Sub Timer2_Tick(sender As System.Object, e As System.EventArgs) Handles Timer2.Tick
Time += 1
SendKeys.Send("{+L}")
If (Time = 10000) Then
Time = 0
ShiftUP()
Timer1.Enabled = True
Timer2.Enabled = False
End If
End Sub
End Class


I am trying to create an advanced key bot thatll hit q to interact with a process on my computer (I dont care if it interacts with all processes or that specific process). When I hit z it is supposed to start an infinite loop of hitting the q key and then holding down shift for a time before starting again with hitting the q key again. This code above keeps giving me an error annoyingly and Im not sure whats wrong with it.

The error is: "A call to PInvoke function WindowsApplication1!WindowsApplication1.Form1::MapVirtualKey has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."

Continue reading...
 
Back
Top