How to use the Sendkeys Command!
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
3 posts
Page 1 of 1
****ALL CODING DONE BY ME IS IN VB 2010!****
Ok, I figured since I'm a new member, it'd be good to share a little of my knowledge that took a bit of google-ing to find. This tutorial covers how to create a program that uses the Sendkeys command.
Start off by Adding one button and three check boxes to your program.
![Image]()
Next, click your button and add this code:
Once you click on Button1, the program will look to see which check box is checked and will do the code of the checked one.
Let's continue with our coding before further explanation:
Ok, now, double click on your first checkbox to edit its code. (This check box's name should be "Open Notepad (Recommended)")
Add this code to checkbox1:
I'll now explain the entire coding of the button.
When you click button1, it the program will check to see which checkbox is selected, if none are selected nothing will happen. If checkbox1 is selected, however, the program will open notepad and type "10101010101010101010110101010101010101010101010101001" using sendkeys.
(Notepad is opened using
If checkbox2 is selected, then the program will 'loop' "10101010101010101010110101010101010101010101010101001"
over and over again until the program is shut down.
Finally, if checkbox3 is selected, the program will open notepad and loop "10101010101010101010110101010101010101010101010101001"
over and over again.
By editing this code on each button, you can change what each one says:
P.s. The download contains a royalty-free icon, completely safe for free use on any project including this one!
Ok, I figured since I'm a new member, it'd be good to share a little of my knowledge that took a bit of google-ing to find. This tutorial covers how to create a program that uses the Sendkeys command.
Start off by Adding one button and three check boxes to your program.

Next, click your button and add this code:
Code: Select all
Here's a bit of an explanation of the code above:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
If CheckBox1.Checked Then
Dim retVal As Object
retVal = Shell("Notepad", vbNormalFocus)
SendKeys.Send("10101010101010101010110101010101010101010101010101001")
ElseIf CheckBox2.Checked Then
If MsgBox("You are about to send 10 on a repeating loop, the only way to stop it is by forcing the program to shut down. Continue?", _
MsgBoxStyle.YesNo, "Notepad Loop") = Windows.Forms.DialogResult.Yes Then
H:
SendKeys.Send("10101010101010101010110101010101010101010101010101001")
GoTo H
Else
SendKeys.Send("10101010101010101010110101010101010101010101010101001")
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
If CheckBox3.Checked Then
Try
If MsgBox("You are about to send 10 to notepad on a repeating loop, the only way to stop it is by forcing the program to shut down. Continue?", _
MsgBoxStyle.YesNo, "Notepad Loop") = Windows.Forms.DialogResult.Yes Then
Dim retVal As Object
retVal = Shell("Notepad", vbNormalFocus)
J:
SendKeys.Send("10101010101010101010110101010101010101010101010101001")
GoTo J
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Once you click on Button1, the program will look to see which check box is checked and will do the code of the checked one.
Let's continue with our coding before further explanation:
Ok, now, double click on your first checkbox to edit its code. (This check box's name should be "Open Notepad (Recommended)")
Add this code to checkbox1:
Code: Select all
Next, double click on Checbox2 and add the following code: (Name this box "Loop")
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
CheckBox3.Checked = False
CheckBox3.Enabled = False
CheckBox2.Checked = False
CheckBox2.Enabled = False
Else
CheckBox3.Enabled = True
CheckBox2.Enabled = True
End If
End Sub
Code: Select all
Finally, add a third button along with this code: (Name this button "Start Open Notepad and Loop")
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.Checked Then
CheckBox1.Checked = False
CheckBox1.Enabled = False
CheckBox3.Checked = False
CheckBox3.Enabled = False
Else
CheckBox1.Enabled = True
CheckBox3.Enabled = True
End If
End Sub
Code: Select all
You should now have fully functional checkboxes and button. Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
If CheckBox3.Checked Then
CheckBox1.Checked = False
CheckBox1.Enabled = False
CheckBox2.Checked = False
CheckBox2.Enabled = False
Else
CheckBox1.Enabled = True
CheckBox2.Enabled = True
End If
End Sub
I'll now explain the entire coding of the button.
When you click button1, it the program will check to see which checkbox is selected, if none are selected nothing will happen. If checkbox1 is selected, however, the program will open notepad and type "10101010101010101010110101010101010101010101010101001" using sendkeys.
(Notepad is opened using
Code: Select all
This will open notepad and focus on it.)Dim retVal As Object
retVal = Shell("Notepad", vbNormalFocus)
If checkbox2 is selected, then the program will 'loop' "10101010101010101010110101010101010101010101010101001"
over and over again until the program is shut down.
Finally, if checkbox3 is selected, the program will open notepad and loop "10101010101010101010110101010101010101010101010101001"
over and over again.
By editing this code on each button, you can change what each one says:
Code: Select all
I know the title says using the sendkeys command, but this tutorial also covered opening and focusing on a program using If CheckBox1.Checked Then
SendKeys.Send("YOUR MESSAGE")
Code: Select all
I hope you enjoyed this tutorial, and if you have questions or want more pictures, etc, just ask! Dim retVal As Object
retVal = Shell("Notepad", vbNormalFocus)

P.s. The download contains a royalty-free icon, completely safe for free use on any project including this one!

You do not have the required permissions to view the files attached to this post.
Last edited by 2cool4cereal2 on Sat Oct 16, 2010 9:39 pm, edited 1 time in total.
I think it would be good to add a part that checks whether notepad has focus during the sendkeys loop.
mandai wrote:I think it would be good to add a part that checks whether notepad has focus during the sendkeys loop.Hmmm, that does sound interesting. Maybe I'll look into that. But, really, this isn't a very serious project, this was just a joke to leave running on my brother's computer to freak him out.
I bet there are a lot of features to be added. Thanks for your idea.

Last bumped by 2cool4cereal2 on Thu Nov 25, 2010 1:55 am.
3 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023