
Originally Posted by
Gill Bates
So you're pretty much talking about an auto-clicker?
Be more specific. What are you trying to achieve with your program? What is it for?
IF, by any chance, you want to make one Form pop up at a click of a button, use "Form1".Show(). Replace text inside " " with your Form's name.
To hide the previous form when the other form opens, use Me.Hide()
I wanna send a click to another process from my program like notepad.exe, it works when the notepad isn't hidden so it makes the notepad popup and sends the click or keys.
But what if the process is hidden with winhide.exe or as example HiddeX? It doesn't work for hidden programs.
Full program:
It has a hack in the resources, it manually writes the hack to a new location and starts it hidden from there.
And clicks anywhere in the hack to activate it and wait for the game process, otherwise it won't get activated.
I tried to send the click while I start the program normally and not hidden and it works, but when I hide it it doesn't work.
So is there another method to send clicks else than the mentioned in my code?
Note: the followiing clicks/keys send code for calc.
Code:
Imports System.Runtime.InteropServices
Public Class Form1
Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Dim Tm As New Timer
Private Declare Auto Function FindWindowa Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Auto Function PostMessage Lib "USER32.DLL" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean
Private Const MK_LBUTTON = &H1
Private Const WM_LBUTTONDOWN = &H201
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const EM_REPLACESEL = &HC2
Private Const LeftMouseDown As Integer = 2
Private Const LeftMouseUp As Integer = 4
<DllImport("user32.dll")> _
Private Shared Function SendInput( _
ByVal nInputs As Integer, _
ByVal pInputs() As INPUT, _
ByVal cbSize As Integer) As Integer
End Function
<StructLayout(LayoutKind.Explicit)> _
Private Structure INPUT
'Field offset 32 bit machine 4
'64 bit machine 8
<FieldOffset(0)> _
Public type As Integer
<FieldOffset(8)> _
Public mi As MOUSEINPUT
<FieldOffset(8)> _
Public ki As KEYBDINPUT
<FieldOffset(8)> _
Public hi As HARDWAREINPUT
End Structure
Private Structure MOUSEINPUT
Public dx As Integer
Public dy As Integer
Public mouseData As Integer
Public dwFlags As Integer
Public time As Integer
Public dwExtraInfo As IntPtr
End Structure
Private Structure KEYBDINPUT
Public wVk As Short
Public wScan As Short
Public dwFlags As Integer
Public time As Integer
Public dwExtraInfo As IntPtr
End Structure
Private Structure HARDWAREINPUT
Public uMsg As Integer
Public wParamL As Short
Public wParamH As Short
End Structure
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Public Shared Function FindWindow( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
End Function
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Public Shared Function ShowWindow( _
ByVal hWnd As IntPtr, _
ByVal nCmdShow As Integer) As Boolean
End Function
<System.Runtime.InteropServices.DllImport("user32.dll")> _
Public Shared Function GetWindowThreadProcessId( _
ByVal hWnd As IntPtr, _
ByVal lpwdProcessId As IntPtr) As IntPtr
End Function
Private Enum ShowWindowCommand As Integer
Hide = 0
Show = 5
Minimize = 6
Restore = 9
End Enum
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As ShowWindowCommand) As Boolean
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)>
Private Shared Function IsWindow(ByVal hWnd As IntPtr) As Boolean
End Function
Private Declare Auto Function IsIconic Lib "user32.dll" (ByVal hwnd As IntPtr) As Boolean
Private calc_hWnd As IntPtr
Private Function LoadResourceToDisk(ByVal Resource As Byte(),
ByVal TargetFile As String) As Boolean
Try
Dim BufferFileStream As New IO.FileStream(TargetFile, IO.FileMode.Create, IO.FileAccess.Write)
BufferFileStream.Write(Resource, 0, Resource.Length)
BufferFileStream.Close()
Return True
Catch ex As Exception
Throw New Exception(ex.Message, ex.InnerException)
Return False
End Try
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadResourceToDisk(My.Resources.Hack, "C:\Windows\System32\hack.exe")
Dim test As New Process
Try
test.StartInfo.FileName = "hack.exe"
test.Start()
test.WaitForInputIdle(-1)
Dim tmp_hWnd As IntPtr
For i As Integer = 1 To 10
tmp_hWnd = test.MainWindowHandle
If Not tmp_hWnd.Equals(IntPtr.Zero) Then Exit For
Threading.Thread.Sleep(100)
Next
If Not tmp_hWnd.Equals(IntPtr.Zero) Then
' ShowWindow(tmp_hWnd, ShowWindowCommand.Minimize)
ShowWindow(tmp_hWnd, ShowWindowCommand.Hide)
calc_hWnd = tmp_hWnd
Else
MessageBox.Show("Unable to load the main hack resources!" & vbNewLine & "Please contact the creator of this hack.")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Threading.Thread.Sleep(5000)
' Dim ProcID As String
' ProcID = Shell("CALC.EXE", AppWinStyle.NormalFocus)
AppActivate("hack.exe")
Threading.Thread.Sleep(5000)
mouse_event(&H2, 0, 0, 0, 1)
mouse_event(&H4, 0, 0, 0, 1)
Threading.Thread.Sleep(5000)
SendKeys.SendWait("{ENTER}")
End Sub
Private Sub a()
Dim ProcID As Integer
' Start the Calculator application, and store the process id.
ProcID = Shell("CALC.EXE", AppWinStyle.NormalFocus)
' Activate the Calculator application.
AppActivate(ProcID)
' Send the keystrokes to the Calculator application.
mouse_event(&H2, 0, 0, 0, 1)
mouse_event(&H4, 0, 0, 0, 1)
End Sub
End Class