I want to make a simple program that will click certain keys on my keyboard at a certain interval. I have VB10. Could someone provide me with some code?
Printable View
I want to make a simple program that will click certain keys on my keyboard at a certain interval. I have VB10. Could someone provide me with some code?
What Keys, what interval, any code inside the keys?
Okay i figured it out, which was fun, working out the errors(having the letter f wrote infinitely :D)
You will need a timer1 and then just this code.
Code:Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Interval = 10000 '10 seconds
My.Computer.Keyboard.SendKeys("f", True)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub
End Class
IF you want it to write to any specific file use this
found this at http://msdn.microsoft.com/en-us/library/ms127847.aspxCode: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.
Use a timer and send a different key on each click. That would be the way to get the interval in there. Look up SendKeys for the key presses....maybe. Actually, after reading what Joshlad suggested, it does occur to me that there could be multiple ways to read that question. I was thinking that your goal was to send keys presses to some other program, but that isn't necessarily the case. Perhaps a bit more description would be good.
EDIT: Wow, I think I need to refresh my browser faster. You had it solved before I even started writing.
I just want the program to hit the keys 6 and 7 every 5 seconds. Thanks for all the assistance!
use a button also to enable the timer, and begin keysCode:Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Interval = 5000 '5 seconds
My.Computer.Keyboard.SendKeys("6", True)
My.Computer.Keyboard.SendKeys("7", True)
End Sub
sub button_click 'you finish it
Timer1.Enabled = True
End Sub
End Class
Okay thank you!