Visual Basic Explorer
Visual Basic Explorer
 Navigation
 Home


 Coding
 Source Code

 FAQ Center

 VB Tips

 Downloads

 ToolBox

 Tutorials

 VB Games

 VB News

 VB Award

 VB Forums



 Affiliates
 Planet Source Code

 Rent a Coder

 DirectX4VB


 Misc
 Search

 Feedback

 Advertise

 About


Need to hire
a VB coder?

Please support our sponsor:

 Home 
 Site Map 
 Forums 
 News 
 Feedback 

 

Capture Keyboard Input
'------------------------------------------------------
'How To: Capture Keyboard Input
'Posted: June 1998
'From: "Robert L. Walsh" rlwalsh@capecod.net
'------------------------------------------------------
Keywords to see in on-line help: KeyPreview property, KeyDown, KeyUp
and KeyPress events, ActiveControl property.

 
If you need to capture a user`s keyboard input _before_ the keystroke
reaches any of the controls mounted on a form, set your form's
KeyPreview property to True, and process each keystroke in the
form`s KeyDown, KeyUp or KeyPress events. Use the KeyPress event
for regular alphanumeric (ANSI) keystrokes and the KeyDown or KeyUp
events for all other keys (Escape, Backspace, Enter, Arrow keys,
Function Keys, etc.). A simple example:

 
Private Sub Form_KeyPress(KeyAscii As Integer)

If ActiveControl.Name = "txtName" Then 'If txtName has the focus...
If KeyAscii < 65 Or KeyAscii > 90 Then 'If keystroke is NOT a capital letter.
If KeyAscii >=97 And KeyAscii <=122 Then'If lower case...
KeyAcsii = (KeyAscii Or 32) 'Convert to upper case.
Else
KeyAscii = 0 'Set keystroke to zero.
End If
End If

 
The above is a brief example of the control your code can have over
keyboard input. The code fragment simply filters out any characters
that are not upper case. If the character received is lower case, it is
converted to caps, otherwise the character is zeroed out. Setting the
keystroke value to zero will be interpreted by most controls as a null
character and will therefore be ignored. You can also set the
keystroke to some other default value depending on the control
receiving the keystroke.


Downloads

In IE right-click and select 'Save Target As...' or in Netscape right-click and select 'Save Link As...'

 

View Plain Text View Plain Text
Download Demo Project Not Available
View Code Online Not Available





Home | About | What's New | Source Code | FAQ | Tips & Tricks | Downloads | ToolBox | Tutorials | Game Programming | VB Award | Search | VB Forums | Feedback | VBNews | Copyright & Disclaimer | Advertise | Privacy Policy |

Quick searches: Site Search | Advanced Site Search 

Copyright 2002 by Exhedra Solutions, Inc.
By using this site you agree to its terms and conditions
VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc.