1
votes

Is it normal behavior for a THotkey to not allow the same hotkey twice?

Here is what I mean.

Say I set the hotkey to Ctrl+Shift+X. I then do something else, and come back to change it. While I am holding down Ctrl and Shift, I realize I dont want to change the hotkey anyway, so I press X while holding Ctrl+Shift. Now the THotkey rejects it. I let go of all the keys, and try the same combination again. It still wont let me assign that key. Even if I click somewhere else on my form, and go back and try the same combination, it wont let me!

Why is that? How can I prevent that?

Thanks!

1
This doesn't happen when I try it (Delphi 2009, Windows 7). Notice that the THotkey is a wrapper for a standard Windows control, that is, the control isn't written in Delphi. It is not even a modified (in Delphi) standard edit control; rather, the 'hot key control' is a part of the Microsoft Windows operating system. Therefore, its behaviour depends not on Delphi version [unless there are issues with the VCL wrapping part of it], but possibly on the Windows version. Just tried it: It works in Windows 95 with Delphi 4, too. - Andreas Rejbrand
@Andreas - I am running Windows 7, could that be the issue? - Jeff
(1) Your app needs to have the focus for your hotkey to fire in the app. (2) Your handler has run into a loop/exit condition that makes it not to execute the main part of your handler. Please paste the code for your key-handler in the question. - Johan
@Johan, this isn't a question of firing the hotkey at run time. This is a question of setting the property at design time. - Rob Kennedy
@Jeff: And then you answered your own question. - Andreas Rejbrand

1 Answers

7
votes

When your THotKey control loses focus, you say you register the hotkey system-wide. When you re-enter the THotKey control, the original value is still registered, so when you press that key combination, the OS intercepts it because it's a registered key combination. The THotKey control never sees it.

You need to unregister the hotkey while the THotKey control has focus.