Locking Keyboard (arrow Keys)

Hello experts,
pls. provide me the code to lock the arrow keys of keyboard.
i mean i dont want the user to use arrow keys untill some other event happens.
i have many controls on which i want to disable arrow keys for some time, so using keydown event will not be a good choice.
Can it be done without API.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
Without KeyDown AND without API :... don't think so.

Now, do you know that you can set the Form's "KeyPreview" to true, use the event KeyDown (checking the ActiveControl) and set the keycode to 0 to remove that key....
At least, that is what I would do...
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics TeacherCommented:
The KeyPreview won't work with some controls as when they have the focus they process these keystrokes, take action and then dispose of them before the form ever gets notified (kinda breaks the whole point of KeyPreview eh?).

The only foolproof way would be to use a low-level keyboard hook and trap the arrow keys.  Here is an example:


> many controls on which i want to disable arrow keys for some time, so using keydown event will not be ...

You can make a control array and do it in one keydown event for all textboxes. And second control array for comboboxes.

Or you can make a class which processes keydown event using WithEvents statement ... see http:Q_20252419.html#6716423 "Form Handling (Tabs & Arrows)" - the only difference is in procedure Test:

Private Sub Test(KeyCode As Integer)
    Select Case KeyCode
    Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown
        KeyCode = 0
    End Select
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.