开发者

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 reall开发者_Python百科y 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


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜