Post: Visual Basic Program Minimized Help
11-23-2011, 12:21 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); So i made this AutoClicker
You must login or register to view this content.

When you are using the program (On top)
It works. But when you minimize the program the hotkeys don't work. How can i make this program so when it is
minimized or in the system tray it will work.

Aka when i press F1 it will start clicking

Here is my code.

    Public Class Autoclicker
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)


Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.F2 Then
Timer1.Start()
Else
If e.KeyCode = Keys.F3 Then
Timer1.Stop()

End If
End If

End Sub


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
KeyPreview = True
AutoSizeMode = False



End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Start()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Stop()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = TextBox1.Text + 1



End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Windows.Forms.Cursor.Position = New System.Drawing.Point(Windows.Forms.Cursor.Position)
mouse_event(&H2, 0, 0, 0, 1)
mouse_event(&H4, 0, 0, 0, 1)
End Sub



Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
System.Diagnostics.Process.Start("mailto:" & "[email protected]")
End Sub

End Class




Take a look and help me out. Thanks
(adsbygoogle = window.adsbygoogle || []).push({});
11-23-2011, 09:16 PM #11
Originally posted by Epic
Like I stated in my previous post, the method I demonstrated for importing user32.dll only works on newer versions of Visual Basic .NET.

First, try removing the End Function from the GetAsyncKeyState declaration, see if that fixes it, if not, proceed to step two:

Second, try replacing the function declaration for GetAsyncKeyState with:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer

Just replace the whole function (including the End Function).

If that doesn't work, let me know, and also tell me what version of the .NET framework you are using and what version of Visual Basic .NET (and the version of the studio, for example: 2008, 2010, etc.).

If you have any further questions, let me know!




I am using visual basic 2008 express.

When i added the new fucntion i got tons of errors. :S As you see i am learning this language and this is my second project with the language.

You must login or register to view this content.
11-23-2011, 10:00 PM #12
Epic?
Awe-Inspiring
Originally posted by xThaSlothx View Post
I am using visual basic 2008 express.

When i added the new fucntion i got tons of errors. :S As you see i am learning this language and this is my second project with the language.

You must login or register to view this content.


Without your code those errors are meaningless. Also, I don't know what to tell you, the code I've given you functions on both Visual Basic 2010 and 2008 (I tested it out myself), it's probably an error in your implementation. I'd suggest you read over the resources I've previously linked you to.

Also, if this is just your second project, perhaps you should choose something easier. I'm not saying "give up and quit this project", I'm saying that its clearly beyond your ability as of this time, and that you should choose something easier, and come back to it later.
11-23-2011, 10:03 PM #13
Originally posted by Epic
v

Originally posted by Sublimity
v


Okay so i followed that tutorial for the Getasynckeystate

And my end result is when i run it. It starts automatically clicking as soon as it opens without any hotkeys or buttons being pressed.

Here is my updated code


    

Public Class Form1
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
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)
--------------------------------------------------------------------------------------------------------------------------------------------------------














Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick



Dim F2 As Boolean

Dim F3 As Boolean




F2 = GetAsyncKeyState(Keys.F2)

F3 = GetAsyncKeyState(Keys.F3)





If Keys.F2 = True Then



Timer2.Start()



End If
If Keys.F3 = True Then
Timer2.Stop()
End If

End Sub


Private Sub Timer2_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Timer1.start()

End Sub
End Class


:/



Edit:

Another thought i had. Doesn't work. No errors though

Full Form Code
    
Public Class Form1
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
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)


Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.F2 Then
Timer1.Start()
Else
If e.KeyCode = Keys.F3 Then
Timer1.Stop()

End If
End If

End Sub


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
KeyPreview = True
AutoSizeMode = False



End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Start()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Stop()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = TextBox1.Text + 1



End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
System.Diagnostics.Process.Start("mailto:" & "[email protected]")
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Windows.Forms.Cursor.Position = New System.Drawing.Point(Windows.Forms.Cursor.Position)
mouse_event(&H2, 0, 0, 0, 1)
mouse_event(&H4, 0, 0, 0, 1)

Dim F2 As Boolean

Dim F3 As Boolean




F2 = GetAsyncKeyState(Keys.F2)

F3 = GetAsyncKeyState(Keys.F3)





If Keys.F2 = True Then
Timer1.Start()
End If
If Keys.F3 = True Then
Timer1.Stop()
End If

End Sub

End Class

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo