lab12
lab12

Reputation: 6448

Disable HotKeys When Typing - VB6

In my VB6 program, I have tons of hotkeys such as X, A, D... ETC . I also have a chat system in it, where everytime I use the characters X or A it will do the actions of those hotkeys. For example, if X was to close the application (not that it really does), when I am typing "fiXing" into my chat textbox, it will close the application. Can anyone tell me how to disable the hotkeys when typing EXCEPT the Enter Key?

thanks,

Kevin

Upvotes: 2

Views: 1884

Answers (2)

raven
raven

Reputation: 18135

In the chat TextBox's GotFocus event set a flag to disable your hotkeys. Then re-enable them in the TextBox's LostFocus event.

I don't know how you trap your hotkeys, but the code to set the flag is pretty simple:

Private suppressHotkeys As Boolean

Private Sub txtChat_GotFocus()
  suppressHotkeys = True
End Sub

Private Sub txtChat_LostFocus()
  suppressHotkeys = False
End Sub

Then in the code that traps the hotkeys, just check the flag:

If (Not suppressHotkeys) Then
  //process hotkey
End If

Upvotes: 1

jac
jac

Reputation: 9726

It would probably be better to use a key combination for your hot keys. It is more common to press say Ctrl+X or Alt+X. You would test for them in either the KeyDown or KeyUp events.

If KeyCode = vbKeyX And (Shift And vbCtrlMask = vbCtrlMask) Then
    ' Do something
End If

Upvotes: 0

Related Questions