Handling Keyboard KeyPress Event in VB

Posted by Chvrsri under VB.NET category on | Points: 40 | Views : 4806
For Keyboard Key Press Event we can handle it using this way in VB

The below mentioned code snippet shows how to handle KeyBoard Key Presss event
Select Case KeyAscii
Case 48 To 57
' ignore if Allow Digits is unchecked
If chkallowdigits.Value = 0 Then
KeyAscii = 0 ' ignore
End If
Case 65 To 90:
'check whether lower case is selected
If optlower.Value Then
keyascii = KeyAscii + 32 ' convert to lower
End If
Case 97 To 122:
'check whether upper case is selected
If optupper.Value Then
KeyAscii = KeyAscii - 32 ' convert to upper
End If
End Select

Cheers !!! Hope It Helps Some One

The Ascii values notation is

The ASCII codes are as follows:

Letters A to Z=65 to 90
Letters a to z=97 to 122
Digits 0 to 9=48 to 57

Use These Controls on your page :

Form1 Caption Keyboard Events Demo
Label1 Caption Code
Text1 Text ""
Frame1 Caption Convert To
Option1 Name OptUpper
Caption &Upper
Option2 Name OptLower
Caption &Lower
Check1 Name Chkallowdigits
Caption &Allow Digits
Command1 Name Cmdexit
Caption &Exit

Comments or Responses

Login to post response