Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making certain key's not work.

Status
Not open for further replies.

mark01

Technical User
Jan 17, 2001
600
US
Is there anyway to make an app disable any of the keyboard key's? So you can't push "Alt" or "T" or the "Windows" key...
 
VB has predefined constants for most every key on the keyboard; do a search in VB Help or the Microsoft site for "keycode constants". They're fairly mnemonic- the <CTRL> key is vbKeyControl, the "+" sign on the keypad is vbKeyPlus, etc.

You'll want to check in the KeyPress event for the form/control. Using a textbox for an example, it would look something like:
Code:
Private Sub MyTextbox_KeyPress(KeyAscii As Integer)

  If KeyAscii = vbKeyControl Then KeyAscii = 0

End Sub

All you're doing is changing the keycode value from whatever they pressed (that you don't want) to Null (or whatever). They press the <CTRL> key, you change it to Ø (null), nothing happens in the textbox. If you want to trap for 2+ keys, either build an If...ElseIf...Else block or a Select Case statement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top