Send Keys - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This is a tutorial on how to get send keys or trigger the computer keyboard certain keys in Visual Basic .NET

Let's say you are making a touchscreen keyboard and reached a point where you want to program the backspace button, or the space button, or even the scroll lock button. You want to trigger those keys and make it look like a user actually clicked on them.

Send Backspace Button:

Assuming you have a button on your form labeled as Backspace. Below is the code that will be used to trigger the backspace button:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        My.Computer.Keyboard.SendKeys("{BACKSPACE}")
    End Sub

Send a String along with the Enter Button:

You can also send a string before triggering the Enter button:

 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        My.Computer.Keyboard.SendKeys("Hello" + "{ENTER}")
    End Sub

Special Buttons Codes List

BACKSPACE {BACKSPACE} or {BS}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
CLEAR {CLEAR}
DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER (numeric keypad) {ENTER}
ENTER ~
ESC {ESCAPE} or {ESC}
HELP {HELP}
HOME {HOME}
INS {INSERT}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
RETURN {RETURN}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 through F15 {F1} through {F15}


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.