Keypress Events

be58d2003

Regular
Joined
Mar 23, 2003
Messages
81
Location
Antioch, California
Sorry if this topic has been posted before, but I am very new to this programming stuff (except for writing Basic on the Commodore 64 many moons ago). What I want to know, and can't seem to find is... how to I get VB.NET to respond to keyboard input?

e.g. If the user press the CAPSLOCK key for instance, I may want to show him/her whether the capslock has been turned on/off through the use of a label, etc.

Can someone please help?

P.S. I am using VB.NET Standard (No C# or anything, just the standard Visual Basic).
 
You are exactly on the right track, I'd recommend the "KeyDown" event, though.

However - these events are fired by single controls on the screen. So what you basically need to do is program a "key_down" eventhandler sub and then attach this sub to all your controls and the form itself using the AddHandler statement.
 
Visual Basic:
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Insert Then
            Label1.Enabled = True
        End If
    End Sub
Thanks for the reply, I happened to find a post that gave a little info on the subject... And, this is what I got! It works like I want, but now I need to figure out how to make it understand whether the INSERT (in this instance) is ON or OFF and display it respectively.

But, am I on the right track with this code?
 
Last edited:
Back
Top