views:

199

answers:

2

Hey guys,

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

+1  A: 

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
raven
Do you know how the code would look like?
Kevin
Ok.. I am still bewildered by the code you just posted... :/. I don't get it.. In the If statement do I put in the code where it involves the hotkeys?
Kevin
A: 

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
Beaner