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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW DO I BLOCK OR INTERCEPT THE KEYBOARD Del & Arrow keys 3

Status
Not open for further replies.

TNN

Programmer
Sep 13, 2000
417
US
The keyboard Del & Arrow keys, when pressed, do not generate a KeyPress event, therefore i am unable to block their use from the user. How do I block their use???

All other ASCII characters do generate a KeyPress event.

I need to have the user be able to click in the text box but not be able to alter it's contents. From that text box the user is able to tab thru to other text boxes and make entries.
TNN, Tom


TOM
 
Hi.
I can't do anything about arrows; sorry. But nothing isn't lost! You need the user to be able to click on a textBox but don't want him to alter the content? The property TextBox.Locked will surely satisfies your needs.
 
You should be able to trap arrow-keys and delete-key presses in the Key_Up and Key_Down events.

Hope this helps

Daren
Must think of a witty signature
 
Sure it might. But the real question's about how to trap the scanCode? Because the Ascii argument doesn't seem to consider the keypress. Or maybe we doesn't use it the good way; I didn't found anything about this in the vb help.
 
Printable characters generate a KeyPress event
All keys generate a KeyDown and KeyUp event. A typical keydown event header is:

Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)

I think that KeyCode will resolve Oak's concern Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
As DarenNM And johnwm have mentioned:

Public Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
Case vbKeyDown, vbKeyUp, vbKeyRight, vbKeyLeft
'Disable
KeyCode = 0
End Select

End Sub [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
To trap the arrow and delete keys you could use
Code:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)

    Select Case KeyCode
    
        Case vbKeyUp: 'Up-arrow
            
            'Code to do what you want here
            'Cancel the keystroke
            KeyCode = 0
            
        Case vbKeyDown: 'Down-arrow
        
            'Code to do what you want here
            'Cancel the keystroke
            KeyCode = 0
        
        Case vbKeyLeft: 'Left-arrow
            
            'Code to do what you want here
            'Cancel the keystroke
            KeyCode = 0
        
        Case vbKeyRight: 'Right-arrow
        
            'Code to do what you want here
            'Cancel the keystroke
            KeyCode = 0
        
        Case vbKeyDelete: 'Delete key
    
            'Code to do what you want here
            'Cancel the keystroke
            KeyCode = 0
            
    End Select 'KeyCode

End Sub

If you didn't want to do anything specific with each key, you just wanted to cancel it:
Code:
    Select Case KeyCode
    
        Case vbKeyUp, vbKeyDown, vbKeyLeft, vbKeyRight, vbKeyDelete:
            
            'Code to do what you want here
            'Cancel the keystroke
            KeyCode = 0
            
    End Select 'KeyCode

Hope this helps

Daren
Must think of a witty signature
 
DarenNM,
CCLINT,

Thank You. I did not know you could cancel a keystroke with the KeyCode=0. I used this in the Form Keydown event and works great to cancel user keystrokes for arrow keys and Del key.

Thanks again. TNN, Tom

TOM
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top