Get the Pressed Key - Visual Basic .NET

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

This is a tutorial on how to capture the pressed key in Visual Basic .NET

This code works when the form is focused. To get the pressed key even that the form is not in focus, see the keylogger tutorial

Private Sub Form1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        If Asc(e.KeyChar) > 1 Then
            MsgBox("You have pressed " & e.KeyChar & " key")
            e.Handled = True
        End If
    End Sub

While the form is active, press any key, you will get a message box with the key pressed displayed.


Share This

Home | About | Contact | Privacy Policy

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