Setting a toggle key - vb.net

I am currently making an autoclicker with human randomization.
The issue i am having is that i have no clue how to make a thing that you can bind a key and then make it run. This is my code so far, and also if you have any idea on how to improve the code then PLEASE share it, I mostly need to improve my randomization.
How can i make a thing so users can set their toggle key?
Public Class Form1
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_RIGHTDOWN = &H8
Private Const MOUSEEVENTF_RIGHTUP = &H10
Declare Function mouse_autoClicker Lib "user32.dll" Alias "mouse_event" (ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean
Private Sub StartClick()
System.Windows.Forms.Cursor.Position = New System.Drawing.Point(System.Windows.Forms.Cursor.Position)
Call mouse_autoClicker(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Call mouse_autoClicker(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub
Private Sub TrackStart_Scroll(sender As Object, e As EventArgs) Handles TrackStart.Scroll
If TrackStart.Value > TrackEnd.Value Then
TrackStart.Value = TrackEnd.Value
End If
valstart.Text = trackstart.Value
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "ClickDevastator v.0.7"
End Sub
Private Sub TrackEnd_Scroll(sender As Object, e As EventArgs) Handles trackend.Scroll
If trackend.Value < trackstart.Value Then
trackend.Value = trackstart.Value
End If
ValEnd.Text = trackend.Value
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim rnd As New Random
Dim ClickString As Integer = rnd.Next(Val(valstart.Text), Val(ValEnd.Text))
txtRnd.Text = ClickString.ToString()
Timer2.Enabled = True
For i As Integer = 0 To Val(txtRnd.Text) - 1
StartClick()
Next
End Sub
Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnstart.Click
If btnstart.Text = "Start" Then
Timer1.Enabled = True
btnstart.Text = "Stop"
btnstart.ForeColor = Color.Red
ElseIf btnstart.Text = "Stop" Then
Timer1.Enabled = False
btnstart.Text = "Start"
btnstart.ForeColor = Color.LawnGreen
End If
End Sub
Private Sub btnClick_Click(sender As Object, e As EventArgs) Handles btnclick.Click
txtClick.Text = Val(txtClick.Text) + 1
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
valstart.Text = Date.Now.ToString("hh : mm : ss")
End Sub
Private Sub Timer1_Disposed(sender As Object, e As EventArgs) Handles Timer1.Disposed
Timer2.Enabled = False
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then
If btnstart.Text = "Stop" Then
btnstart.PerformClick()
End If
End If
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs)
End Sub
Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btnstart.Click
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles txtRnd.TextChanged
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnclick.Click
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles ValEnd.Click
End Sub
Private Sub label1_Click_1(sender As Object, e As EventArgs) Handles valstart.Click
End Sub
Private Sub BindingNavigatorDeleteItem_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Label1_Click_2(sender As Object, e As EventArgs)
End Sub
Private Sub trackstart_Scroll_1(sender As Object, e As EventArgs) Handles trackstart.Scroll
End Sub
Private Sub Label1_Click_3(sender As Object, e As EventArgs)
End Sub
Private Sub Label1_Click_4(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
End Class

A Toggle in code works on boolean values like this...
Button2.Enabled = Not (Button2.Enabled)

Related

How to use numpad as input in vb calculator

Basically I've been searching for weeks now but I cannot find a good example of using the numpad as an input for calculator.
Private Sub Form1_KeyPress(ByVal KeyAscii As _MSForms.ReturnInteger)
lblOutput.Text = lblOutput.Text & Chr(KeyAscii)
If KeyAscii >= vbKeyNumpad0() And KeyAscii <= vbKeyNumpad9() Then
lblOutput.Text = lblOutput.Text & Chr(KeyAscii)
End If
End Sub
Option Explicit On
Public Class Form1
Dim chrOperator As Char
Dim varFirstVal As Integer
Private Sub Form1_KeyPress(ByVal KeyAscii As _MSForms.ReturnInteger)
lblOutput.Text = lblOutput.Text & Chr(KeyAscii)
If KeyAscii >= vbKeyNumpad0() And KeyAscii <= vbKeyNumpad9() Then
lblOutput.Text = lblOutput.Text & Chr(KeyAscii)
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
KeyPreview = True
End Sub
Private Sub ButtonAppend(number As Integer)
If CInt(lblOutput.Text) = 0 Then
lblOutput.Text = CType(number, String)
Else
lblOutput.Text = lblOutput.Text & number
End If
End Sub
Private Sub operation(operand As String)
chrOperator = CChar(operand)
varFirstVal = CInt(lblOutput.Text)
lblOutput.Text = CType(0, String)
End Sub
Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
ButtonAppend(1)
End Sub
Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
ButtonAppend(2)
End Sub
Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click
ButtonAppend(3)
End Sub
Private Sub btn4_Click(sender As Object, e As EventArgs) Handles btn4.Click
ButtonAppend(4)
End Sub
Private Sub btn5_Click(sender As Object, e As EventArgs) Handles btn5.Click
ButtonAppend(5)
End Sub
Private Sub btn6_Click(sender As Object, e As EventArgs) Handles btn6.Click
ButtonAppend(6)
End Sub
Private Sub btn7_Click(sender As Object, e As EventArgs) Handles btn7.Click
ButtonAppend(7)
End Sub
Private Sub btn8_Click(sender As Object, e As EventArgs) Handles btn8.Click
ButtonAppend(8)
End Sub
Private Sub btn9_Click(sender As Object, e As EventArgs) Handles btn9.Click
ButtonAppend(9)
End Sub
Private Sub btn0_Click(sender As Object, e As EventArgs) Handles btn0.Click
ButtonAppend(0)
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
lblOutput.Text = "0"
varFirstVal = 0
End Sub
Private Sub btnEquals_Click(sender As Object, e As EventArgs) Handles btnEquals.Click
Select Case chrOperator
Case CChar("A")
lblOutput.Text = CType(varFirstVal + CInt(lblOutput.Text), String)
Case CChar("S")
lblOutput.Text = CType(varFirstVal - CInt(lblOutput.Text), String)
Case CChar("M")
lblOutput.Text = CType(varFirstVal * CInt(lblOutput.Text), String)
Case CChar("D")
lblOutput.Text = CType(varFirstVal / CInt(lblOutput.Text), String)
End Select
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
operation("A")
End Sub
Private Sub btnSub_Click(sender As Object, e As EventArgs) Handles btnSub.Click
operation("S")
End Sub
Private Sub btnMultiply_Click(sender As Object, e As EventArgs) Handles btnMultiply.Click
operation("M")
End Sub
Private Sub btnDivide_Click(sender As Object, e As EventArgs) Handles btnDivide.Click
operation("S")
End Sub
End Class
What I want to get out of it is being able to use the numpad and never have to click anything on screen for the calculator to work.

Simplifying multiple similar 'private subs' in VB

I'm writing a VB program that has multiple positions where when the user hovers over an item, the same image appears.
Currently I have:
Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
PictureBox1.Image = Image.FromFile(picturePath)
End Sub
Private Sub PictureBox2_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox2.MouseMove
PictureBox2.Image = Image.FromFile(picturePath)
End Sub
Private Sub PictureBox3_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox3.MouseMove
PictureBox3.Image = Image.FromFile(picturePath)
End Sub
Private Sub PictureBox4_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox4.MouseMove
PictureBox4.Image = Image.FromFile(picturePath)
End Sub
Private Sub PictureBox5_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox5.MouseMove
PictureBox5.Image = Image.FromFile(picturePath)
End Sub
Private Sub PictureBox6_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox6.MouseMove
PictureBox6.Image = Image.FromFile(picturePath)
End Sub
Private Sub PictureBox7_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox7.MouseMove
PictureBox7.Image = Image.FromFile(picturePath)
End Sub
This works fine, however, I am looking to condense my code. Surely there is a way of making this into just 1 or 2 private subs.
Note that this is just a snippet of my code.
The names of the objects are easily named PictureBox1, PictureBox2 etc.
Regards
Hugo.
Private Sub PictureBox_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove, PictureBox2.MouseMove, PictureBox3.MouseMove, PictureBox4.MouseMove, PictureBox5.MouseMove, PictureBox6.MouseMove, PictureBox7.MouseMove
DirectCast(sender, PictureBox).Image = Image.FromFile(picturePath)
End Sub

Background image moving vb.net

I'm trying to create a small game, but I'm getting trouble.
I would like the background image to move as a loop when the player is moving across the map. The following code is a sample of what I want but the reverse.
Public Class Form1
Private WithEvents Tmr As New Timer With {.Interval = 40}
Private water As New Bitmap("C:\TestFolder\Water.png")
Private waterposition As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Size = New Size(240, 74)
Tmr.Start()
End Sub
Private Sub Tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Tmr.Tick
waterposition += 1
If waterposition = water.Width Then waterposition = 0
PictureBox1.Invalidate()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.DrawImage(water, waterposition, 0)
If waterposition > 0 Then e.Graphics.DrawImage(water, 0 - (water.Width - waterposition), 0)
End Sub End class
And now, when I'm trying to reverse it (from right to left) The image won't redraw.
Private Sub Tmr_Tick(sender As Object, e As EventArgs) Handles Tmr.Tick
waterposition -= 1
If waterposition = 0 Then waterposition = water.Width
PictureBox1.Invalidate()
End Sub
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.DrawImage(water, waterposition, 0)
If waterposition < 0 Then e.Graphics.DrawImage(water, (water.Width + waterposition), 0)
End Sub
Any suggestion? Thanks

Covering Panel with another

Private Sub frmitem_Load(sender As Object, e As EventArgs) Handles MyBase.Load
pnldeposit.Visible = False
pnlwithdraw.Visible = False
End Sub
Private Sub cmdideposit_Click(sender As Object, e As EventArgs) Handles cmdideposit.Click
pnldeposit.Visible = True
pnlwithdraw.Visible = False
End Sub
Private Sub cmdiwithdraw_Click(sender As Object, e As EventArgs) Handles cmdiwithdraw.Click
pnlwithdraw.Visible = True
pnldeposit.Visible = False
End Sub
//i am having problem with this form. i want to show the first panel which is successful, but the problem is showing the second panel. it is not working, im using buttons btw. help me. Thank you in advance :D
Here is a quick example using BringToFront. With both panels having the same Location and being the same Size.
Public Class Form1
Private switchPanels As Boolean
Private Sub btn_Click(sender As Object, e As EventArgs) Handles btn.Click
switchPanels = Not switchPanels
If switchPanels Then
Panel1.BringToFront()
Else
Panel2.BringToFront()
End If
End Sub
End Class
Private Sub cmdideposit_Click(sender As Object, e As EventArgs) Handles cmdideposit.Click
pnldeposit.Visible = True
pnlwithdraw.Visible = False
pnlreport.Visible = False
End Sub
Private Sub cmddcancel_Click(sender As Object, e As EventArgs)
pnldeposit.Hide()
End Sub
Private Sub cmdiwithdraw_Click(sender As Object, e As EventArgs) Handles cmdiwithdraw.Click
pnlwithdraw.Visible = True
pnlreport.Visible = False
End Sub
Private Sub cmdwclear_Click(sender As Object, e As EventArgs) Handles cmdwclear.Click
pnlwithdraw.Visible = False
End Sub
Private Sub cmdireport_Click(sender As Object, e As EventArgs) Handles cmdireport.Click
pnlreport.Visible = True
End Sub
//thank you for sharing your idea! i found how it works. thanks! :D

WebBrowser1.Navigate loop request

How can i make this code to loop urls continuously in Webbrowser1, after run trough these links one time.
This is the code i have so far, but when i run this, the Webbrowser stop with last url, wich is google.com. What i want to do is when the last url is reached i want it to start from top again, and run trough links again and again, until i exit the program.
Public Class Form1
Private WithEvents backgroundWorker1 As System.ComponentModel.BackgroundWorker
Dim l As New List(Of String)
Dim flagDC As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Hide()
Button3.Show()
l = New List(Of String)
l.Add("http://bbc.com/sipeu/php/zq.php")
l.Add("http://google.com")
l.Add("http://DCWC.com/sipeu/us.php")
l.Add("http://google.com")
l.Add("http://example.com/sipeu/v.php")
l.Add("http://google.com")
backgroundWorker1 = New System.ComponentModel.BackgroundWorker
backgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker2_DoWork(ByVal sender As System.Object,
ByVal e As System.ComponentModel.DoWorkEventArgs) _
Handles backgroundWorker1.DoWork
For Each www In l
flagDC = False
WebBrowser1.Navigate(www)
Do
Loop While Not flagDC
Next
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) _
Handles WebBrowser1.DocumentCompleted
System.Threading.Thread.Sleep(1000)
flagDC = True
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Button3.Hide()
ChangeUserAgent("troll001_v2-agent34")
WebBrowser1.Navigate("http://example.com/welcome.php")
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs)
End Sub