on November 28, 2009 by Adam in Uncategorized, Comments (0)
Point and Click While Away from Keyboard
Do you ever wish there was a simple program out there that would record a point on the screen that you can set to click that exact area a certain amount of seconds from now?
Well now you can, using Visual Basic I whipped together this program for use in some applications that would like you to be present to use (so you can see their advertisements etc.)
There are many more modifications that can be done to this program, but i’ll include the bare-bones code for you to expand on. You may also download an executable of the file here. (see code below)
”’ <summary>
”’ Click, record position, set time till computer clicks that postition, and wait
”’ By the way there is no visual countdown
”’ </summary>
”’ <remarks>Created by Adam Lee at adamrlee.org</remarks>
Public Class Form1
Public Const DOWN = &H2 ‘ left button down
Public Const UP = &H4 ‘ left button up
Dim xpos As Integer
Dim ypos As Integer
Dim t1 As Integer = 0
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
Button1_Click()
End If
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then
Button1_Click()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 100
Timer1.Start()
t1 = 1
End Sub
Private Sub Button1_Click() Handles Button1.Click
If t1 = 1 Then
Timer1.Stop()
t1 = 0
xpos = TextBox1.Text
ypos = TextBox2.Text
TextBox1.BackColor = Color.Gray
TextBox2.BackColor = Color.Gray
Button1.Text = “Click here to Reset”
ElseIf t1 = 0 Then
Timer1.Start()
t1 = 1
Button1.Text = “Press Enter To Set Position”
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
TextBox1.Text = Cursor.Position.X
TextBox2.Text = Cursor.Position.Y
End Sub
Private Declare Sub mouse_event Lib “user32.dll” ( _
ByVal dwFlags As Int32, _
ByVal dx As Int32, _
ByVal dy As Int32, _
ByVal cButtons As Int32, _
ByVal dwExtraInfo As Int32 _
)
Private Declare Function SetCursorPos Lib “user32.dll” ( _
ByVal X As Int32, _
ByVal Y As Int32 _
) As Boolean
Private Sub Button2_Click() Handles Button2.Click
If IsNumeric(TextBox3.Text) = True Then
Timer2.Interval = TextBox3.Text * 1000
Timer2.Start()
Else
MsgBox(“Time must be represented as an integer”)
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Timer2.Stop()
SetCursorPos(xpos, ypos)
clickMouse()
If RadioButton1.Checked = True Then
clickMouse()
End If
End Sub
Public Sub clickMouse()
mouse_event(DOWN, 0, 0, 0, 0)
mouse_event(UP, 0, 0, 0, 0)
End Sub
Private Sub TextBox3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.Click
TextBox3.SelectAll()
End Sub
Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
Button2_Click()
End Sub
Private Sub TextBox3_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.MouseHover
ToolTip1.Show(“type number of seconds”, TextBox3)
End Sub
End Class
No Comments
Leave a comment