Hi all

Is it possible to trap the ESC key during the execution of an mdi form? I want the esc key to be trapped and when it is pressed I want the current form to be unloaded. Is it possible?

Any help will be appreciated.

Rajesh Khanna

Recommended Answers

All 2 Replies

Hi, I think It is not possible in VB6. You have to write code for unload for every form.

Well there are few ways how can you do it.

Input api call in loop (heavy duty).
In code window there is events for from, left side is object or function drop down combo you must chose form1 or however is your form called and on right side is event for objects also drop down combo (e.g. load, unload enc...) choose keydown.

Here is little code that will help you well it least i hope it will help.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Const ESC = vbKeyEscape

If KeyCode = ESC Then
    MsgBox "you pressed esscape"
End If

End Sub

But it will only do its work if form is active.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.