VB.Net/Event/Key Action

Материал из VB Эксперт
Перейти к: навигация, поиск

Displaying information about a user-pressed key

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class MainClass
   Shared Sub Main()
        Dim myform As Form = New FrmKeyDemo()
        Application.Run(myform)
   End Sub " Main
End Class
Public Class FrmKeyDemo
   Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
   Public Sub New()
      MyBase.New()
      "This call is required by the Windows Form Designer.
      InitializeComponent()
      "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
         If Not (components Is Nothing) Then
            components.Dispose()
         End If
      End If
      MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents lblInformation As System.Windows.Forms.Label
   Friend WithEvents lblCharacter As System.Windows.Forms.Label
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.Container
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
      Me.lblInformation = New System.Windows.Forms.Label()
      Me.lblCharacter = New System.Windows.Forms.Label()
      Me.SuspendLayout()
      "
      "lblInformation
      "
      Me.lblInformation.Font = New System.Drawing.Font("Microsoft Sans Serif", 12!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
      Me.lblInformation.Location = New System.Drawing.Point(8, 56)
      Me.lblInformation.Name = "lblInformation"
      Me.lblInformation.Size = New System.Drawing.Size(176, 136)
      Me.lblInformation.TabIndex = 1
      "
      "lblCharacter
      "
      Me.lblCharacter.Font = New System.Drawing.Font("Microsoft Sans Serif", 12!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
      Me.lblCharacter.Location = New System.Drawing.Point(8, 16)
      Me.lblCharacter.Name = "lblCharacter"
      Me.lblCharacter.Size = New System.Drawing.Size(168, 23)
      Me.lblCharacter.TabIndex = 0
      "
      "FrmKeyDemo
      "
      Me.AutoScaleBaseSize = New System.Drawing.Size(9, 22)
      Me.ClientSize = New System.Drawing.Size(192, 205)
      Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblInformation, Me.lblCharacter})
      Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
      Me.Name = "FrmKeyDemo"
      Me.Text = "KeyDemo"
      Me.ResumeLayout(False)
   End Sub
#End Region
   Private Sub FrmKeyDemo_KeyPress(ByVal sender As System.Object, _
      ByVal e As System.Windows.Forms.KeyPressEventArgs) _
      Handles MyBase.KeyPress
      lblCharacter.Text = "Key pressed: " & e.KeyChar
   End Sub
   Private Sub FrmKeyDemo_KeyDown(ByVal sender As System.Object, _
      ByVal e As System.Windows.Forms.KeyEventArgs) _
      Handles MyBase.KeyDown
      lblInformation.Text = ""
      " if key is Alt
      If e.Alt Then
         lblInformation.Text &= "Alt: Yes" & vbCrLf
      Else
         lblInformation.Text &= "Alt: No" & vbCrLf
      End If
      " if key is Shift
      If e.Shift Then
         lblInformation.Text &= "Shift: Yes" & vbCrLf
      Else
         lblInformation.Text &= "Shift: No" & vbCrLf
      End If
      " if key is Ctrl
      If e.Control Then
         lblInformation.Text &= "Ctrl: Yes" & vbCrLf
      Else
         lblInformation.Text &= "Ctrl: No" & vbCrLf
      End If
      lblInformation.Text &= "KeyCode: " & e.KeyCode.ToString & _
            vbCrLf & "KeyData: " & e.KeyData.ToString & _
            vbCrLf & "KeyValue: " & e.KeyValue
   End Sub " FrmKeyDemo_KeyDown
End Class


Display key event in Fake Keyboard

Imports System.Windows.Forms
Imports System.Drawing

Public Class MainClass
    Public Shared Sub Main()
      Application.Run(New FrmTypingApplication)
    End Sub
End Class

Public Class FrmTypingApplication
   Inherits System.Windows.Forms.Form
   " reference to last Button pressed
   Private m_btnLastButton As Button
#Region " Windows Form Designer generated code "
   Public Sub New()
      MyBase.New()
      "This call is required by the Windows Form Designer.
      InitializeComponent()
      "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
         If Not (components Is Nothing) Then
            components.Dispose()
         End If
      End If
      MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   Friend WithEvents lblPrompt As System.Windows.Forms.Label
   Friend WithEvents txtOutput As System.Windows.Forms.TextBox
   Friend WithEvents btnF1 As System.Windows.Forms.Button
   Friend WithEvents btnF2 As System.Windows.Forms.Button
   Friend WithEvents btnF3 As System.Windows.Forms.Button
   Friend WithEvents btnF4 As System.Windows.Forms.Button
   Friend WithEvents btnF5 As System.Windows.Forms.Button
   Friend WithEvents btnF6 As System.Windows.Forms.Button
   Friend WithEvents btnF7 As System.Windows.Forms.Button
   Friend WithEvents btnF8 As System.Windows.Forms.Button
   Friend WithEvents btnF9 As System.Windows.Forms.Button
   Friend WithEvents btnF10 As System.Windows.Forms.Button
   Friend WithEvents btnF11 As System.Windows.Forms.Button
   Friend WithEvents btnF12 As System.Windows.Forms.Button
   Friend WithEvents btn0 As System.Windows.Forms.Button
   Friend WithEvents btn1 As System.Windows.Forms.Button
   Friend WithEvents btn2 As System.Windows.Forms.Button
   Friend WithEvents btn3 As System.Windows.Forms.Button
   Friend WithEvents btn4 As System.Windows.Forms.Button
   Friend WithEvents btn5 As System.Windows.Forms.Button
   Friend WithEvents btn6 As System.Windows.Forms.Button
   Friend WithEvents btn7 As System.Windows.Forms.Button
   Friend WithEvents btn8 As System.Windows.Forms.Button
   Friend WithEvents btn9 As System.Windows.Forms.Button
   Friend WithEvents btnHyphen As System.Windows.Forms.Button
   Friend WithEvents btnPlus As System.Windows.Forms.Button
   Friend WithEvents btnTilde As System.Windows.Forms.Button
   Friend WithEvents btnTab As System.Windows.Forms.Button
   Friend WithEvents btnCaps As System.Windows.Forms.Button
   Friend WithEvents btnShiftLeft As System.Windows.Forms.Button
   Friend WithEvents btnCtrlLeft As System.Windows.Forms.Button
   Friend WithEvents btnFn As System.Windows.Forms.Button
   Friend WithEvents btnAltLeft As System.Windows.Forms.Button
   Friend WithEvents btnSpace As System.Windows.Forms.Button
   Friend WithEvents btnBackspace As System.Windows.Forms.Button
   Friend WithEvents btnSlash As System.Windows.Forms.Button
   Friend WithEvents btnEnter As System.Windows.Forms.Button
   Friend WithEvents btnUp As System.Windows.Forms.Button
   Friend WithEvents btnLeft As System.Windows.Forms.Button
   Friend WithEvents btnDown As System.Windows.Forms.Button
   Friend WithEvents btnRight As System.Windows.Forms.Button
   Friend WithEvents btnLeftBrace As System.Windows.Forms.Button
   Friend WithEvents btnRightBrace As System.Windows.Forms.Button
   Friend WithEvents btnColon As System.Windows.Forms.Button
   Friend WithEvents btnQuote As System.Windows.Forms.Button
   Friend WithEvents btnComma As System.Windows.Forms.Button
   Friend WithEvents btnPeriod As System.Windows.Forms.Button
   Friend WithEvents btnQuestion As System.Windows.Forms.Button
   Friend WithEvents btnA As System.Windows.Forms.Button
   Friend WithEvents btnB As System.Windows.Forms.Button
   Friend WithEvents btnC As System.Windows.Forms.Button
   Friend WithEvents btnD As System.Windows.Forms.Button
   Friend WithEvents btnE As System.Windows.Forms.Button
   Friend WithEvents btnF As System.Windows.Forms.Button
   Friend WithEvents btnG As System.Windows.Forms.Button
   Friend WithEvents btnH As System.Windows.Forms.Button
   Friend WithEvents btnI As System.Windows.Forms.Button
   Friend WithEvents btnJ As System.Windows.Forms.Button
   Friend WithEvents btnK As System.Windows.Forms.Button
   Friend WithEvents btnL As System.Windows.Forms.Button
   Friend WithEvents btnN As System.Windows.Forms.Button
   Friend WithEvents btnO As System.Windows.Forms.Button
   Friend WithEvents btnP As System.Windows.Forms.Button
   Friend WithEvents btnQ As System.Windows.Forms.Button
   Friend WithEvents btnR As System.Windows.Forms.Button
   Friend WithEvents btnS As System.Windows.Forms.Button
   Friend WithEvents btnT As System.Windows.Forms.Button
   Friend WithEvents btnU As System.Windows.Forms.Button
   Friend WithEvents btnV As System.Windows.Forms.Button
   Friend WithEvents btnW As System.Windows.Forms.Button
   Friend WithEvents btnM As System.Windows.Forms.Button
   Friend WithEvents btnX As System.Windows.Forms.Button
   Friend WithEvents btnY As System.Windows.Forms.Button
   Friend WithEvents btnZ As System.Windows.Forms.Button
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
      Me.lblPrompt = New System.Windows.Forms.Label
      Me.txtOutput = New System.Windows.Forms.TextBox
      Me.btnF1 = New System.Windows.Forms.Button
      Me.btnF2 = New System.Windows.Forms.Button
      Me.btnF3 = New System.Windows.Forms.Button
      Me.btnF4 = New System.Windows.Forms.Button
      Me.btnF5 = New System.Windows.Forms.Button
      Me.btnF6 = New System.Windows.Forms.Button
      Me.btnF7 = New System.Windows.Forms.Button
      Me.btnF8 = New System.Windows.Forms.Button
      Me.btnF9 = New System.Windows.Forms.Button
      Me.btnF10 = New System.Windows.Forms.Button
      Me.btnF11 = New System.Windows.Forms.Button
      Me.btnF12 = New System.Windows.Forms.Button
      Me.btn1 = New System.Windows.Forms.Button
      Me.btn2 = New System.Windows.Forms.Button
      Me.btn3 = New System.Windows.Forms.Button
      Me.btn4 = New System.Windows.Forms.Button
      Me.btn5 = New System.Windows.Forms.Button
      Me.btn6 = New System.Windows.Forms.Button
      Me.btn7 = New System.Windows.Forms.Button
      Me.btn8 = New System.Windows.Forms.Button
      Me.btn9 = New System.Windows.Forms.Button
      Me.btn0 = New System.Windows.Forms.Button
      Me.btnHyphen = New System.Windows.Forms.Button
      Me.btnPlus = New System.Windows.Forms.Button
      Me.btnTilde = New System.Windows.Forms.Button
      Me.btnTab = New System.Windows.Forms.Button
      Me.btnCtrlLeft = New System.Windows.Forms.Button
      Me.btnFn = New System.Windows.Forms.Button
      Me.btnAltLeft = New System.Windows.Forms.Button
      Me.btnEnter = New System.Windows.Forms.Button
      Me.btnSlash = New System.Windows.Forms.Button
      Me.btnBackspace = New System.Windows.Forms.Button
      Me.btnSpace = New System.Windows.Forms.Button
      Me.btnCaps = New System.Windows.Forms.Button
      Me.btnShiftLeft = New System.Windows.Forms.Button
      Me.btnUp = New System.Windows.Forms.Button
      Me.btnLeft = New System.Windows.Forms.Button
      Me.btnDown = New System.Windows.Forms.Button
      Me.btnRight = New System.Windows.Forms.Button
      Me.btnLeftBrace = New System.Windows.Forms.Button
      Me.btnRightBrace = New System.Windows.Forms.Button
      Me.btnColon = New System.Windows.Forms.Button
      Me.btnQuote = New System.Windows.Forms.Button
      Me.btnComma = New System.Windows.Forms.Button
      Me.btnPeriod = New System.Windows.Forms.Button
      Me.btnQuestion = New System.Windows.Forms.Button
      Me.btnC = New System.Windows.Forms.Button
      Me.btnB = New System.Windows.Forms.Button
      Me.btnA = New System.Windows.Forms.Button
      Me.btnG = New System.Windows.Forms.Button
      Me.btnF = New System.Windows.Forms.Button
      Me.btnE = New System.Windows.Forms.Button
      Me.btnD = New System.Windows.Forms.Button
      Me.btnK = New System.Windows.Forms.Button
      Me.btnJ = New System.Windows.Forms.Button
      Me.btnI = New System.Windows.Forms.Button
      Me.btnH = New System.Windows.Forms.Button
      Me.btnO = New System.Windows.Forms.Button
      Me.btnN = New System.Windows.Forms.Button
      Me.btnM = New System.Windows.Forms.Button
      Me.btnL = New System.Windows.Forms.Button
      Me.btnT = New System.Windows.Forms.Button
      Me.btnS = New System.Windows.Forms.Button
      Me.btnR = New System.Windows.Forms.Button
      Me.btnQ = New System.Windows.Forms.Button
      Me.btnP = New System.Windows.Forms.Button
      Me.btnY = New System.Windows.Forms.Button
      Me.btnX = New System.Windows.Forms.Button
      Me.btnW = New System.Windows.Forms.Button
      Me.btnV = New System.Windows.Forms.Button
      Me.btnU = New System.Windows.Forms.Button
      Me.btnZ = New System.Windows.Forms.Button
      Me.SuspendLayout()
      "
      "lblPrompt
      "
      Me.lblPrompt.Location = New System.Drawing.Point(32, 8)
      Me.lblPrompt.Name = "lblPrompt"
      Me.lblPrompt.Size = New System.Drawing.Size(408, 40)
      Me.lblPrompt.TabIndex = 64
      Me.lblPrompt.Text = "Type some text using your keyboard."
      "
      "txtOutput
      "
      Me.txtOutput.AcceptsTab = True
      Me.txtOutput.BackColor = System.Drawing.Color.White
      Me.txtOutput.Font = New System.Drawing.Font("Tahoma", 10.2!)
      Me.txtOutput.Location = New System.Drawing.Point(32, 64)
      Me.txtOutput.Multiline = True
      Me.txtOutput.Name = "txtOutput"
      Me.txtOutput.ReadOnly = True
      Me.txtOutput.Size = New System.Drawing.Size(408, 136)
      Me.txtOutput.TabIndex = 0
      Me.txtOutput.Text = ""
      "
      "btnF1
      "
      Me.btnF1.Location = New System.Drawing.Point(48, 216)
      Me.btnF1.Name = "btnF1"
      Me.btnF1.Size = New System.Drawing.Size(32, 23)
      Me.btnF1.TabIndex = 74
      Me.btnF1.Text = "F1"
      "
      "btnF2
      "
      Me.btnF2.Location = New System.Drawing.Point(80, 216)
      Me.btnF2.Name = "btnF2"
      Me.btnF2.Size = New System.Drawing.Size(32, 23)
      Me.btnF2.TabIndex = 72
      Me.btnF2.Text = "F2"
      "
      "btnF3
      "
      Me.btnF3.Location = New System.Drawing.Point(112, 216)
      Me.btnF3.Name = "btnF3"
      Me.btnF3.Size = New System.Drawing.Size(32, 23)
      Me.btnF3.TabIndex = 67
      Me.btnF3.Text = "F3"
      "
      "btnF4
      "
      Me.btnF4.Location = New System.Drawing.Point(144, 216)
      Me.btnF4.Name = "btnF4"
      Me.btnF4.Size = New System.Drawing.Size(32, 23)
      Me.btnF4.TabIndex = 68
      Me.btnF4.Text = "F4"
      "
      "btnF5
      "
      Me.btnF5.Location = New System.Drawing.Point(176, 216)
      Me.btnF5.Name = "btnF5"
      Me.btnF5.Size = New System.Drawing.Size(32, 23)
      Me.btnF5.TabIndex = 69
      Me.btnF5.Text = "F5"
      "
      "btnF6
      "
      Me.btnF6.Location = New System.Drawing.Point(208, 216)
      Me.btnF6.Name = "btnF6"
      Me.btnF6.Size = New System.Drawing.Size(32, 23)
      Me.btnF6.TabIndex = 70
      Me.btnF6.Text = "F6"
      "
      "btnF7
      "
      Me.btnF7.Location = New System.Drawing.Point(240, 216)
      Me.btnF7.Name = "btnF7"
      Me.btnF7.Size = New System.Drawing.Size(32, 23)
      Me.btnF7.TabIndex = 71
      Me.btnF7.Text = "F7"
      "
      "btnF8
      "
      Me.btnF8.Location = New System.Drawing.Point(272, 216)
      Me.btnF8.Name = "btnF8"
      Me.btnF8.Size = New System.Drawing.Size(32, 23)
      Me.btnF8.TabIndex = 72
      Me.btnF8.Text = "F8"
      "
      "btnF9
      "
      Me.btnF9.Location = New System.Drawing.Point(304, 216)
      Me.btnF9.Name = "btnF9"
      Me.btnF9.Size = New System.Drawing.Size(32, 23)
      Me.btnF9.TabIndex = 73
      Me.btnF9.Text = "F9"
      "
      "btnF10
      "
      Me.btnF10.Location = New System.Drawing.Point(336, 216)
      Me.btnF10.Name = "btnF10"
      Me.btnF10.Size = New System.Drawing.Size(32, 23)
      Me.btnF10.TabIndex = 74
      Me.btnF10.Text = "F10"
      "
      "btnF11
      "
      Me.btnF11.Location = New System.Drawing.Point(368, 216)
      Me.btnF11.Name = "btnF11"
      Me.btnF11.Size = New System.Drawing.Size(32, 23)
      Me.btnF11.TabIndex = 75
      Me.btnF11.Text = "F11"
      "
      "btnF12
      "
      Me.btnF12.Location = New System.Drawing.Point(400, 216)
      Me.btnF12.Name = "btnF12"
      Me.btnF12.Size = New System.Drawing.Size(32, 23)
      Me.btnF12.TabIndex = 76
      Me.btnF12.Text = "F12"
      "
      "btn1
      "
      Me.btn1.Location = New System.Drawing.Point(80, 240)
      Me.btn1.Name = "btn1"
      Me.btn1.Size = New System.Drawing.Size(24, 23)
      Me.btn1.TabIndex = 77
      Me.btn1.Text = "1"
      "
      "btn2
      "
      Me.btn2.Location = New System.Drawing.Point(104, 240)
      Me.btn2.Name = "btn2"
      Me.btn2.Size = New System.Drawing.Size(24, 23)
      Me.btn2.TabIndex = 78
      Me.btn2.Text = "2"
      "
      "btn3
      "
      Me.btn3.Location = New System.Drawing.Point(128, 240)
      Me.btn3.Name = "btn3"
      Me.btn3.Size = New System.Drawing.Size(24, 23)
      Me.btn3.TabIndex = 79
      Me.btn3.Text = "3"
      "
      "btn4
      "
      Me.btn4.Location = New System.Drawing.Point(152, 240)
      Me.btn4.Name = "btn4"
      Me.btn4.Size = New System.Drawing.Size(24, 23)
      Me.btn4.TabIndex = 80
      Me.btn4.Text = "4"
      "
      "btn5
      "
      Me.btn5.Location = New System.Drawing.Point(176, 240)
      Me.btn5.Name = "btn5"
      Me.btn5.Size = New System.Drawing.Size(24, 23)
      Me.btn5.TabIndex = 81
      Me.btn5.Text = "5"
      "
      "btn6
      "
      Me.btn6.Location = New System.Drawing.Point(200, 240)
      Me.btn6.Name = "btn6"
      Me.btn6.Size = New System.Drawing.Size(24, 23)
      Me.btn6.TabIndex = 82
      Me.btn6.Text = "6"
      "
      "btn7
      "
      Me.btn7.Location = New System.Drawing.Point(224, 240)
      Me.btn7.Name = "btn7"
      Me.btn7.Size = New System.Drawing.Size(24, 23)
      Me.btn7.TabIndex = 83
      Me.btn7.Text = "7"
      "
      "btn8
      "
      Me.btn8.Location = New System.Drawing.Point(248, 240)
      Me.btn8.Name = "btn8"
      Me.btn8.Size = New System.Drawing.Size(24, 23)
      Me.btn8.TabIndex = 84
      Me.btn8.Text = "8"
      "
      "btn9
      "
      Me.btn9.Location = New System.Drawing.Point(272, 240)
      Me.btn9.Name = "btn9"
      Me.btn9.Size = New System.Drawing.Size(24, 23)
      Me.btn9.TabIndex = 85
      Me.btn9.Text = "9"
      "
      "btn0
      "
      Me.btn0.Location = New System.Drawing.Point(296, 240)
      Me.btn0.Name = "btn0"
      Me.btn0.Size = New System.Drawing.Size(24, 23)
      Me.btn0.TabIndex = 86
      Me.btn0.Text = "0"
      "
      "btnHyphen
      "
      Me.btnHyphen.Location = New System.Drawing.Point(320, 240)
      Me.btnHyphen.Name = "btnHyphen"
      Me.btnHyphen.Size = New System.Drawing.Size(24, 23)
      Me.btnHyphen.TabIndex = 87
      Me.btnHyphen.Text = "-"
      "
      "btnPlus
      "
      Me.btnPlus.Location = New System.Drawing.Point(344, 240)
      Me.btnPlus.Name = "btnPlus"
      Me.btnPlus.Size = New System.Drawing.Size(24, 23)
      Me.btnPlus.TabIndex = 88
      Me.btnPlus.Text = "+"
      "
      "btnTilde
      "
      Me.btnTilde.Location = New System.Drawing.Point(32, 240)
      Me.btnTilde.Name = "btnTilde"
      Me.btnTilde.Size = New System.Drawing.Size(48, 23)
      Me.btnTilde.TabIndex = 89
      Me.btnTilde.Text = "~"
      "
      "btnTab
      "
      Me.btnTab.Location = New System.Drawing.Point(32, 264)
      Me.btnTab.Name = "btnTab"
      Me.btnTab.Size = New System.Drawing.Size(64, 23)
      Me.btnTab.TabIndex = 90
      Me.btnTab.Text = "Tab"
      "
      "btnCtrlLeft
      "
      Me.btnCtrlLeft.Location = New System.Drawing.Point(32, 336)
      Me.btnCtrlLeft.Name = "btnCtrlLeft"
      Me.btnCtrlLeft.Size = New System.Drawing.Size(56, 23)
      Me.btnCtrlLeft.TabIndex = 91
      Me.btnCtrlLeft.Text = "Ctrl"
      "
      "btnFn
      "
      Me.btnFn.Enabled = False
      Me.btnFn.Location = New System.Drawing.Point(88, 336)
      Me.btnFn.Name = "btnFn"
      Me.btnFn.Size = New System.Drawing.Size(32, 23)
      Me.btnFn.TabIndex = 92
      Me.btnFn.Text = "Fn"
      "
      "btnAltLeft
      "
      Me.btnAltLeft.Location = New System.Drawing.Point(120, 336)
      Me.btnAltLeft.Name = "btnAltLeft"
      Me.btnAltLeft.Size = New System.Drawing.Size(32, 23)
      Me.btnAltLeft.TabIndex = 93
      Me.btnAltLeft.Text = "Alt"
      "
      "btnEnter
      "
      Me.btnEnter.Location = New System.Drawing.Point(368, 288)
      Me.btnEnter.Name = "btnEnter"
      Me.btnEnter.Size = New System.Drawing.Size(72, 23)
      Me.btnEnter.TabIndex = 94
      Me.btnEnter.Text = "Enter"
      "
      "btnSlash
      "
      Me.btnSlash.Location = New System.Drawing.Point(384, 264)
      Me.btnSlash.Name = "btnSlash"
      Me.btnSlash.Size = New System.Drawing.Size(56, 23)
      Me.btnSlash.TabIndex = 95
      Me.btnSlash.Text = "\"
      "
      "btnBackspace
      "
      Me.btnBackspace.Location = New System.Drawing.Point(368, 240)
      Me.btnBackspace.Name = "btnBackspace"
      Me.btnBackspace.Size = New System.Drawing.Size(72, 23)
      Me.btnBackspace.TabIndex = 96
      Me.btnBackspace.Text = "Backspace"
      "
      "btnSpace
      "
      Me.btnSpace.Location = New System.Drawing.Point(152, 336)
      Me.btnSpace.Name = "btnSpace"
      Me.btnSpace.Size = New System.Drawing.Size(144, 23)
      Me.btnSpace.TabIndex = 97
      "
      "btnCaps
      "
      Me.btnCaps.Location = New System.Drawing.Point(32, 288)
      Me.btnCaps.Name = "btnCaps"
      Me.btnCaps.Size = New System.Drawing.Size(72, 23)
      Me.btnCaps.TabIndex = 98
      Me.btnCaps.Text = "Caps Lock"
      "
      "btnShiftLeft
      "
      Me.btnShiftLeft.Location = New System.Drawing.Point(32, 312)
      Me.btnShiftLeft.Name = "btnShiftLeft"
      Me.btnShiftLeft.Size = New System.Drawing.Size(88, 23)
      Me.btnShiftLeft.TabIndex = 99
      Me.btnShiftLeft.Text = "Shift"
      "
      "btnUp
      "
      Me.btnUp.Location = New System.Drawing.Point(384, 312)
      Me.btnUp.Name = "btnUp"
      Me.btnUp.Size = New System.Drawing.Size(24, 23)
      Me.btnUp.TabIndex = 100
      Me.btnUp.Text = "^"
      "
      "btnLeft
      "
      Me.btnLeft.Location = New System.Drawing.Point(360, 336)
      Me.btnLeft.Name = "btnLeft"
      Me.btnLeft.Size = New System.Drawing.Size(24, 23)
      Me.btnLeft.TabIndex = 101
      Me.btnLeft.Text = "<"
      "
      "btnDown
      "
      Me.btnDown.Location = New System.Drawing.Point(384, 336)
      Me.btnDown.Name = "btnDown"
      Me.btnDown.Size = New System.Drawing.Size(24, 23)
      Me.btnDown.TabIndex = 102
      Me.btnDown.Text = "v"
      "
      "btnRight
      "
      Me.btnRight.Location = New System.Drawing.Point(408, 336)
      Me.btnRight.Name = "btnRight"
      Me.btnRight.Size = New System.Drawing.Size(24, 23)
      Me.btnRight.TabIndex = 103
      Me.btnRight.Text = ">"
      "
      "btnLeftBrace
      "
      Me.btnLeftBrace.Location = New System.Drawing.Point(336, 264)
      Me.btnLeftBrace.Name = "btnLeftBrace"
      Me.btnLeftBrace.Size = New System.Drawing.Size(24, 23)
      Me.btnLeftBrace.TabIndex = 104
      Me.btnLeftBrace.Text = "["
      "
      "btnRightBrace
      "
      Me.btnRightBrace.Location = New System.Drawing.Point(360, 264)
      Me.btnRightBrace.Name = "btnRightBrace"
      Me.btnRightBrace.Size = New System.Drawing.Size(24, 23)
      Me.btnRightBrace.TabIndex = 105
      Me.btnRightBrace.Text = "]"
      "
      "btnColon
      "
      Me.btnColon.Location = New System.Drawing.Point(320, 288)
      Me.btnColon.Name = "btnColon"
      Me.btnColon.Size = New System.Drawing.Size(24, 23)
      Me.btnColon.TabIndex = 106
      Me.btnColon.Text = ":"
      "
      "btnQuote
      "
      Me.btnQuote.Location = New System.Drawing.Point(344, 288)
      Me.btnQuote.Name = "btnQuote"
      Me.btnQuote.Size = New System.Drawing.Size(24, 23)
      Me.btnQuote.TabIndex = 107
      Me.btnQuote.Text = """"
      "
      "btnComma
      "
      Me.btnComma.Location = New System.Drawing.Point(288, 312)
      Me.btnComma.Name = "btnComma"
      Me.btnComma.Size = New System.Drawing.Size(24, 23)
      Me.btnComma.TabIndex = 108
      Me.btnComma.Text = ","
      "
      "btnPeriod
      "
      Me.btnPeriod.Location = New System.Drawing.Point(312, 312)
      Me.btnPeriod.Name = "btnPeriod"
      Me.btnPeriod.Size = New System.Drawing.Size(24, 23)
      Me.btnPeriod.TabIndex = 109
      Me.btnPeriod.Text = "."
      "
      "btnQuestion
      "
      Me.btnQuestion.Location = New System.Drawing.Point(336, 312)
      Me.btnQuestion.Name = "btnQuestion"
      Me.btnQuestion.Size = New System.Drawing.Size(24, 23)
      Me.btnQuestion.TabIndex = 110
      Me.btnQuestion.Text = "?"
      "
      "btnC
      "
      Me.btnC.Location = New System.Drawing.Point(168, 312)
      Me.btnC.Name = "btnC"
      Me.btnC.Size = New System.Drawing.Size(24, 23)
      Me.btnC.TabIndex = 111
      Me.btnC.Text = "C"
      "
      "btnB
      "
      Me.btnB.Location = New System.Drawing.Point(216, 312)
      Me.btnB.Name = "btnB"
      Me.btnB.Size = New System.Drawing.Size(24, 23)
      Me.btnB.TabIndex = 112
      Me.btnB.Text = "B"
      "
      "btnA
      "
      Me.btnA.Location = New System.Drawing.Point(104, 288)
      Me.btnA.Name = "btnA"
      Me.btnA.Size = New System.Drawing.Size(24, 23)
      Me.btnA.TabIndex = 113
      Me.btnA.Text = "A"
      "
      "btnG
      "
      Me.btnG.Location = New System.Drawing.Point(200, 288)
      Me.btnG.Name = "btnG"
      Me.btnG.Size = New System.Drawing.Size(24, 23)
      Me.btnG.TabIndex = 114
      Me.btnG.Text = "G"
      "
      "btnF
      "
      Me.btnF.Location = New System.Drawing.Point(176, 288)
      Me.btnF.Name = "btnF"
      Me.btnF.Size = New System.Drawing.Size(24, 23)
      Me.btnF.TabIndex = 115
      Me.btnF.Text = "F"
      "
      "btnE
      "
      Me.btnE.Location = New System.Drawing.Point(144, 264)
      Me.btnE.Name = "btnE"
      Me.btnE.Size = New System.Drawing.Size(24, 23)
      Me.btnE.TabIndex = 116
      Me.btnE.Text = "E"
      "
      "btnD
      "
      Me.btnD.Location = New System.Drawing.Point(152, 288)
      Me.btnD.Name = "btnD"
      Me.btnD.Size = New System.Drawing.Size(24, 23)
      Me.btnD.TabIndex = 117
      Me.btnD.Text = "D"
      "
      "btnK
      "
      Me.btnK.Location = New System.Drawing.Point(272, 288)
      Me.btnK.Name = "btnK"
      Me.btnK.Size = New System.Drawing.Size(24, 23)
      Me.btnK.TabIndex = 118
      Me.btnK.Text = "K"
      "
      "btnJ
      "
      Me.btnJ.Location = New System.Drawing.Point(248, 288)
      Me.btnJ.Name = "btnJ"
      Me.btnJ.Size = New System.Drawing.Size(24, 23)
      Me.btnJ.TabIndex = 119
      Me.btnJ.Text = "J"
      "
      "btnI
      "
      Me.btnI.Location = New System.Drawing.Point(264, 264)
      Me.btnI.Name = "btnI"
      Me.btnI.Size = New System.Drawing.Size(24, 23)
      Me.btnI.TabIndex = 120
      Me.btnI.Text = "I"
      "
      "btnH
      "
      Me.btnH.Location = New System.Drawing.Point(224, 288)
      Me.btnH.Name = "btnH"
      Me.btnH.Size = New System.Drawing.Size(24, 23)
      Me.btnH.TabIndex = 121
      Me.btnH.Text = "H"
      "
      "btnO
      "
      Me.btnO.Location = New System.Drawing.Point(288, 264)
      Me.btnO.Name = "btnO"
      Me.btnO.Size = New System.Drawing.Size(24, 23)
      Me.btnO.TabIndex = 122
      Me.btnO.Text = "O"
      "
      "btnN
      "
      Me.btnN.Location = New System.Drawing.Point(240, 312)
      Me.btnN.Name = "btnN"
      Me.btnN.Size = New System.Drawing.Size(24, 23)
      Me.btnN.TabIndex = 123
      Me.btnN.Text = "N"
      "
      "btnM
      "
      Me.btnM.Location = New System.Drawing.Point(264, 312)
      Me.btnM.Name = "btnM"
      Me.btnM.Size = New System.Drawing.Size(24, 23)
      Me.btnM.TabIndex = 124
      Me.btnM.Text = "M"
      "
      "btnL
      "
      Me.btnL.Location = New System.Drawing.Point(296, 288)
      Me.btnL.Name = "btnL"
      Me.btnL.Size = New System.Drawing.Size(24, 23)
      Me.btnL.TabIndex = 125
      Me.btnL.Text = "L"
      "
      "btnT
      "
      Me.btnT.Location = New System.Drawing.Point(192, 264)
      Me.btnT.Name = "btnT"
      Me.btnT.Size = New System.Drawing.Size(24, 23)
      Me.btnT.TabIndex = 126
      Me.btnT.Text = "T"
      "
      "btnS
      "
      Me.btnS.Location = New System.Drawing.Point(128, 288)
      Me.btnS.Name = "btnS"
      Me.btnS.Size = New System.Drawing.Size(24, 23)
      Me.btnS.TabIndex = 127
      Me.btnS.Text = "S"
      "
      "btnR
      "
      Me.btnR.Location = New System.Drawing.Point(168, 264)
      Me.btnR.Name = "btnR"
      Me.btnR.Size = New System.Drawing.Size(24, 23)
      Me.btnR.TabIndex = 128
      Me.btnR.Text = "R"
      "
      "btnQ
      "
      Me.btnQ.Location = New System.Drawing.Point(96, 264)
      Me.btnQ.Name = "btnQ"
      Me.btnQ.Size = New System.Drawing.Size(24, 23)
      Me.btnQ.TabIndex = 129
      Me.btnQ.Text = "Q"
      "
      "btnP
      "
      Me.btnP.Location = New System.Drawing.Point(312, 264)
      Me.btnP.Name = "btnP"
      Me.btnP.Size = New System.Drawing.Size(24, 23)
      Me.btnP.TabIndex = 130
      Me.btnP.Text = "P"
      "
      "btnY
      "
      Me.btnY.Location = New System.Drawing.Point(216, 264)
      Me.btnY.Name = "btnY"
      Me.btnY.Size = New System.Drawing.Size(24, 23)
      Me.btnY.TabIndex = 131
      Me.btnY.Text = "Y"
      "
      "btnX
      "
      Me.btnX.Location = New System.Drawing.Point(144, 312)
      Me.btnX.Name = "btnX"
      Me.btnX.Size = New System.Drawing.Size(24, 23)
      Me.btnX.TabIndex = 132
      Me.btnX.Text = "X"
      "
      "btnW
      "
      Me.btnW.Location = New System.Drawing.Point(120, 264)
      Me.btnW.Name = "btnW"
      Me.btnW.Size = New System.Drawing.Size(24, 23)
      Me.btnW.TabIndex = 133
      Me.btnW.Text = "W"
      "
      "btnV
      "
      Me.btnV.Location = New System.Drawing.Point(192, 312)
      Me.btnV.Name = "btnV"
      Me.btnV.Size = New System.Drawing.Size(24, 23)
      Me.btnV.TabIndex = 134
      Me.btnV.Text = "V"
      "
      "btnU
      "
      Me.btnU.Location = New System.Drawing.Point(240, 264)
      Me.btnU.Name = "btnU"
      Me.btnU.Size = New System.Drawing.Size(24, 23)
      Me.btnU.TabIndex = 135
      Me.btnU.Text = "U"
      "
      "btnZ
      "
      Me.btnZ.Location = New System.Drawing.Point(120, 312)
      Me.btnZ.Name = "btnZ"
      Me.btnZ.Size = New System.Drawing.Size(24, 23)
      Me.btnZ.TabIndex = 136
      Me.btnZ.Text = "Z"
      "
      "FrmTypingApplication
      "
      Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
      Me.ClientSize = New System.Drawing.Size(472, 369)
      Me.Controls.Add(Me.btnZ)
      Me.Controls.Add(Me.btnU)
      Me.Controls.Add(Me.btnV)
      Me.Controls.Add(Me.btnW)
      Me.Controls.Add(Me.btnX)
      Me.Controls.Add(Me.btnY)
      Me.Controls.Add(Me.btnP)
      Me.Controls.Add(Me.btnQ)
      Me.Controls.Add(Me.btnR)
      Me.Controls.Add(Me.btnS)
      Me.Controls.Add(Me.btnT)
      Me.Controls.Add(Me.btnL)
      Me.Controls.Add(Me.btnM)
      Me.Controls.Add(Me.btnN)
      Me.Controls.Add(Me.btnO)
      Me.Controls.Add(Me.btnH)
      Me.Controls.Add(Me.btnI)
      Me.Controls.Add(Me.btnJ)
      Me.Controls.Add(Me.btnK)
      Me.Controls.Add(Me.btnD)
      Me.Controls.Add(Me.btnE)
      Me.Controls.Add(Me.btnF)
      Me.Controls.Add(Me.btnG)
      Me.Controls.Add(Me.btnA)
      Me.Controls.Add(Me.btnB)
      Me.Controls.Add(Me.btnC)
      Me.Controls.Add(Me.btnQuestion)
      Me.Controls.Add(Me.btnPeriod)
      Me.Controls.Add(Me.btnComma)
      Me.Controls.Add(Me.btnQuote)
      Me.Controls.Add(Me.btnColon)
      Me.Controls.Add(Me.btnRightBrace)
      Me.Controls.Add(Me.btnLeftBrace)
      Me.Controls.Add(Me.btnRight)
      Me.Controls.Add(Me.btnDown)
      Me.Controls.Add(Me.btnLeft)
      Me.Controls.Add(Me.btnUp)
      Me.Controls.Add(Me.btnShiftLeft)
      Me.Controls.Add(Me.btnCaps)
      Me.Controls.Add(Me.btnSpace)
      Me.Controls.Add(Me.btnBackspace)
      Me.Controls.Add(Me.btnSlash)
      Me.Controls.Add(Me.btnEnter)
      Me.Controls.Add(Me.btnAltLeft)
      Me.Controls.Add(Me.btnFn)
      Me.Controls.Add(Me.btnCtrlLeft)
      Me.Controls.Add(Me.btnTab)
      Me.Controls.Add(Me.btnTilde)
      Me.Controls.Add(Me.btnPlus)
      Me.Controls.Add(Me.btnHyphen)
      Me.Controls.Add(Me.btn0)
      Me.Controls.Add(Me.btn9)
      Me.Controls.Add(Me.btn8)
      Me.Controls.Add(Me.btn7)
      Me.Controls.Add(Me.btn6)
      Me.Controls.Add(Me.btn5)
      Me.Controls.Add(Me.btn4)
      Me.Controls.Add(Me.btn3)
      Me.Controls.Add(Me.btn2)
      Me.Controls.Add(Me.btn1)
      Me.Controls.Add(Me.btnF12)
      Me.Controls.Add(Me.btnF11)
      Me.Controls.Add(Me.btnF10)
      Me.Controls.Add(Me.btnF9)
      Me.Controls.Add(Me.btnF8)
      Me.Controls.Add(Me.btnF7)
      Me.Controls.Add(Me.btnF6)
      Me.Controls.Add(Me.btnF5)
      Me.Controls.Add(Me.btnF4)
      Me.Controls.Add(Me.btnF3)
      Me.Controls.Add(Me.btnF2)
      Me.Controls.Add(Me.btnF1)
      Me.Controls.Add(Me.txtOutput)
      Me.Controls.Add(Me.lblPrompt)
      Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
      Me.Name = "FrmTypingApplication"
      Me.Text = "Typing Application"
      Me.ResumeLayout(False)
   End Sub
#End Region
   
   Private Sub txtOutput_KeyDown(ByVal sender As Object, _
      ByVal e As System.Windows.Forms.KeyEventArgs) _
      Handles txtOutput.KeyDown
      Select Case e.KeyData
         Case Keys.Back 
            ChangeColor(btnBackspace)
         Case Keys.Enter 
            ChangeColor(btnEnter)
         Case Keys.Tab 
            ChangeColor(btnTab)
         Case Keys.Space 
            ChangeColor(btnSpace)
         Case Keys.D0
            ChangeColor(btn0)
         Case Keys.D1
            ChangeColor(btn1)
         Case Keys.D2
            ChangeColor(btn2)
         Case Keys.D3
            ChangeColor(btn3)
         Case Keys.D4
            ChangeColor(btn4)
         Case Keys.D5
            ChangeColor(btn5)
         Case Keys.D6
            ChangeColor(btn6)
         Case Keys.D7
            ChangeColor(btn7)
         Case Keys.D8
            ChangeColor(btn8)
         Case Keys.D9
            ChangeColor(btn9)
         Case Keys.F1 
            ChangeColor(btnF1)
         Case Keys.F2 
            ChangeColor(btnF2)
         Case Keys.F3 
            ChangeColor(btnF3)
         Case Keys.F4 
            ChangeColor(btnF4)
         Case Keys.F5 
            ChangeColor(btnF5)
         Case Keys.F6 
            ChangeColor(btnF6)
         Case Keys.F7 
            ChangeColor(btnF7)
         Case Keys.F8 
            ChangeColor(btnF8)
         Case Keys.F9 
            ChangeColor(btnF9)
         Case Keys.F10
            ChangeColor(btnF10)
         Case Keys.F11
            ChangeColor(btnF11)
         Case Keys.F12
            ChangeColor(btnF12)
         Case Keys.OemOpenBrackets
            ChangeColor(btnLeftBrace)
         Case Keys.OemCloseBrackets
            ChangeColor(btnRightBrace)
         Case Keys.Oemplus
            ChangeColor(btnPlus)
         Case Keys.OemMinus
            ChangeColor(btnHyphen)
         Case Keys.Oemtilde
            ChangeColor(btnTilde)
         Case Keys.OemPipe 
            ChangeColor(btnSlash)
         Case Keys.OemSemicolon 
            ChangeColor(btnColon)
         Case Keys.OemQuotes 
            ChangeColor(btnQuote)
         Case Keys.OemPeriod 
            ChangeColor(btnPeriod)
         Case Keys.Oemcomma
            ChangeColor(btnComma)
         Case Keys.OemQuestion
            ChangeColor(btnQuestion)
         Case Keys.CapsLock
            ChangeColor(btnCaps)
         Case Keys.Down
            ChangeColor(btnDown)
         Case Keys.Up
            ChangeColor(btnUp)
         Case Keys.Left
            ChangeColor(btnLeft)
         Case Keys.Right 
            ChangeColor(btnRight)
         " if a modifier key was pressed
         Case CType(65552, Keys) " Shift key
            ChangeColor(btnShiftLeft)
         Case CType(131089, Keys) " Control key
            ChangeColor(btnCtrlLeft)
         Case CType(262162, Keys) " Alt key
            ChangeColor(btnAltLeft)
      End Select
      txtOutput.Text &= e.KeyData
      
   End Sub 

   Private Sub txtOutput_KeyPress(ByVal sender As Object, _
      ByVal e As System.Windows.Forms.KeyPressEventArgs) _
      Handles txtOutput.KeyPress
      txtOutput.Text &= e.KeyChar
      Select Case Char.ToUpper(e.KeyChar)
         Case Convert.ToChar(Keys.A) " a key
            ChangeColor(btnA)
         Case Convert.ToChar(Keys.B) " b key
            ChangeColor(btnB)
         Case Convert.ToChar(Keys.C) " c key
            ChangeColor(btnC)
         Case Convert.ToChar(Keys.D) " d key
            ChangeColor(btnD)
         Case Convert.ToChar(Keys.E) " e key
            ChangeColor(btnE)
         Case Convert.ToChar(Keys.F) " f key
            ChangeColor(btnF)
         Case Convert.ToChar(Keys.G) " g key
            ChangeColor(btnG)
         Case Convert.ToChar(Keys.H) " h key
            ChangeColor(btnH)
         Case Convert.ToChar(Keys.I) " i key
            ChangeColor(btnI)
         Case Convert.ToChar(Keys.J) " j key
            ChangeColor(btnJ)
         Case Convert.ToChar(Keys.K) " k key
            ChangeColor(btnK)
         Case Convert.ToChar(Keys.L) " l key
            ChangeColor(btnL)
         Case Convert.ToChar(Keys.M) " m key
            ChangeColor(btnM)
         Case Convert.ToChar(Keys.N) " n key
            ChangeColor(btnN)
         Case Convert.ToChar(Keys.O) " o key
            ChangeColor(btnO)
         Case Convert.ToChar(Keys.P) " p key
            ChangeColor(btnP)
         Case Convert.ToChar(Keys.Q) " q key
            ChangeColor(btnQ)
         Case Convert.ToChar(Keys.R) " r key
            ChangeColor(btnR)
         Case Convert.ToChar(Keys.S) " s key
            ChangeColor(btnS)
         Case Convert.ToChar(Keys.T) " t key
            ChangeColor(btnT)
         Case Convert.ToChar(Keys.U) " u key
            ChangeColor(btnU)
         Case Convert.ToChar(Keys.V) " v key
            ChangeColor(btnV)
         Case Convert.ToChar(Keys.W) " w key
            ChangeColor(btnW)
         Case Convert.ToChar(Keys.X) " x key
            ChangeColor(btnX)
         Case Convert.ToChar(Keys.Y) " y key
            ChangeColor(btnY)
         Case Convert.ToChar(Keys.Z) " z key
            ChangeColor(btnZ)
      End Select 
   End Sub 
   Private Sub txtOutput_KeyUp(ByVal sender As Object, _
      ByVal e As System.Windows.Forms.KeyEventArgs) _
      Handles txtOutput.KeyUp
      ResetColor()
   End Sub " txtOutput_KeyUp
   Private Sub ChangeColor(ByVal btnButton As Button)
      ResetColor()
      btnButton.BackColor = Color.Red
      m_btnLastButton = btnButton
   End Sub " ChangeColor
   Private Sub ResetColor()
      If IsNothing(m_btnLastButton) = False Then
         m_btnLastButton.BackColor = _
            m_btnLastButton.DefaultBackColor
      End If 
   End Sub 
End Class


Key action info: data, code, modifier and value

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Resources
Public Class Form1
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        "This call is required by the Windows Form Designer.
        InitializeComponent()
        "Add any initialization after the InitializeComponent() call
    End Sub
    "Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    Friend WithEvents keyDataLabel As System.Windows.Forms.Label
    Friend WithEvents label1 As System.Windows.Forms.Label
    Friend WithEvents label2 As System.Windows.Forms.Label
    Friend WithEvents keyCodeLabel As System.Windows.Forms.Label
    Friend WithEvents modifiersLabel As System.Windows.Forms.Label
    Friend WithEvents label4 As System.Windows.Forms.Label
    Friend WithEvents keyValueLabel As System.Windows.Forms.Label
    Friend WithEvents label5 As System.Windows.Forms.Label
    Friend WithEvents label3 As System.Windows.Forms.Label
    Friend WithEvents keyCharLabel As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.keyDataLabel = New System.Windows.Forms.Label()
        Me.label1 = New System.Windows.Forms.Label()
        Me.label2 = New System.Windows.Forms.Label()
        Me.keyCodeLabel = New System.Windows.Forms.Label()
        Me.modifiersLabel = New System.Windows.Forms.Label()
        Me.label4 = New System.Windows.Forms.Label()
        Me.keyValueLabel = New System.Windows.Forms.Label()
        Me.label5 = New System.Windows.Forms.Label()
        Me.label3 = New System.Windows.Forms.Label()
        Me.keyCharLabel = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        "
        "keyDataLabel
        "
        Me.keyDataLabel.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.keyDataLabel.Location = New System.Drawing.Point(120, 8)
        Me.keyDataLabel.Name = "keyDataLabel"
        Me.keyDataLabel.Size = New System.Drawing.Size(228, 23)
        Me.keyDataLabel.TabIndex = 9
        "
        "label1
        "
        Me.label1.Location = New System.Drawing.Point(8, 8)
        Me.label1.Name = "label1"
        Me.label1.TabIndex = 5
        Me.label1.Text = "KeyData"
        "
        "label2
        "
        Me.label2.Location = New System.Drawing.Point(8, 40)
        Me.label2.Name = "label2"
        Me.label2.TabIndex = 6
        Me.label2.Text = "KeyCode"
        "
        "keyCodeLabel
        "
        Me.keyCodeLabel.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.keyCodeLabel.Location = New System.Drawing.Point(120, 40)
        Me.keyCodeLabel.Name = "keyCodeLabel"
        Me.keyCodeLabel.Size = New System.Drawing.Size(228, 23)
        Me.keyCodeLabel.TabIndex = 10
        "
        "modifiersLabel
        "
        Me.modifiersLabel.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.modifiersLabel.Location = New System.Drawing.Point(120, 72)
        Me.modifiersLabel.Name = "modifiersLabel"
        Me.modifiersLabel.Size = New System.Drawing.Size(228, 23)
        Me.modifiersLabel.TabIndex = 11
        "
        "label4
        "
        Me.label4.Location = New System.Drawing.Point(8, 72)
        Me.label4.Name = "label4"
        Me.label4.TabIndex = 4
        Me.label4.Text = "Modifiers"
        "
        "keyValueLabel
        "
        Me.keyValueLabel.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.keyValueLabel.Location = New System.Drawing.Point(120, 104)
        Me.keyValueLabel.Name = "keyValueLabel"
        Me.keyValueLabel.Size = New System.Drawing.Size(228, 23)
        Me.keyValueLabel.TabIndex = 8
        "
        "label5
        "
        Me.label5.Location = New System.Drawing.Point(8, 104)
        Me.label5.Name = "label5"
        Me.label5.TabIndex = 3
        Me.label5.Text = "KeyValue"
        "
        "label3
        "
        Me.label3.Location = New System.Drawing.Point(8, 136)
        Me.label3.Name = "label3"
        Me.label3.TabIndex = 2
        Me.label3.Text = "KeyChar"
        "
        "keyCharLabel
        "
        Me.keyCharLabel.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.keyCharLabel.Location = New System.Drawing.Point(120, 136)
        Me.keyCharLabel.Name = "keyCharLabel"
        Me.keyCharLabel.Size = New System.Drawing.Size(228, 23)
        Me.keyCharLabel.TabIndex = 7
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(328, 174)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.keyDataLabel, Me.label1, Me.label2, Me.keyCodeLabel, Me.modifiersLabel, Me.label4, Me.keyValueLabel, Me.label5, Me.label3, Me.keyCharLabel})
        Me.Name = "Form1"
        Me.Text = "KeyTest"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        keyDataLabel.Text = e.KeyData.ToString()
        keyCodeLabel.Text = e.KeyCode.ToString()
        modifiersLabel.Text = e.Modifiers.ToString()
        keyValueLabel.Text = e.KeyValue.ToString()
    End Sub
    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        keyCharLabel.Text = e.KeyChar.ToString()
    End Sub
End Class

Public Class MainClass
    Shared Sub Main()
        Dim myform As Form = New  Form1()
        Application.Run(myform)
    End Sub
End Class


Key event: KeyChar code

Imports System
Imports System.Collections
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Printing

Public Class MainClass
    Shared Sub Main()
       Dim form1 As Form = New Form1()
       Application.Run(form1) 
    End Sub
End Class


Public Class Form1
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        "This call is required by the Windows Form Designer.
        InitializeComponent()
        "Add any initialization after the InitializeComponent() call
    End Sub
    "Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.Container
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.SuspendLayout()
        "
        "TextBox1
        "
        Me.TextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TextBox1.Location = New System.Drawing.Point(48, 104)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(192, 27)
        Me.TextBox1.TabIndex = 1
        Me.TextBox1.Text = ""
        "
        "Label1
        "
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(24, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(232, 48)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "Type somthing"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
        Me.ClientSize = New System.Drawing.Size(292, 268)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.TextBox1})
        Me.Name = "Form1"
        Me.Text = "Key Event Examples"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    End Sub
    Private Sub TextBox1_KeyPress(ByVal sender As Object, _
            ByVal e As System.Windows.Forms.KeyPressEventArgs) _
            Handles TextBox1.KeyPress
        If e.KeyChar < "0" Or e.KeyChar > "9" Then
            MessageBox.Show("only digits allowed")
            e.Handled = True
        End If
    End Sub
    
End Class