Disable one key

El Don

Member
Joined
Feb 19, 2009
Messages
8
Programming Experience
Beginner
I need to disable keys using a form, when pressing a button, searching in the forum, I found this:
VB.NET:
If (e.Alt = True) Then
            If (e.KeyData = Keys.F4) Then
                e.Handled = True
            End If
        End If

but I can't get it to work, is there a way to disable keys?

I need to disable a, s, d , f keys, if you could help me, that would be great.
Thanks in advance.
 
if e.KeyData <> Keys.S then
Code here
end if

Just add up more if statements to disable more keys, should work but didn't test though.
 
You should be sure to use short circuit logic when stringing multiple conditions in a row like that:
VB.NET:
If e.KeyCode <> Keys.A AndAlso e.KeyCode <> Keys.S AndAlso e.KeyCode <> Keys.D Then
    'Code
End If
 
Select Case can also be used:
VB.NET:
Select Case e.KeyCode
    Case Keys.A, Keys.S, Keys.D, Keys.F
        e.Handled = True
End Select
 
Back
Top