Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Creating System Hotkeys using THotKey (can it be done?)

This topic is 5961 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know how to test for and register/unregister system hotkeys, but what I''d really like to do is let the user select their hotkeys using the THotKey control. I know the actual THotKey.HotKey property is nothing more than a TShortCut, what I don''t know is how to figure out what that value represents. TShortCut appears to be nothing more than a word (correct me if I''m wrong), however while I know CTRL is 17, and F1 is 112 (ASCII decimal), CTRL-F1 yields 16496? Does anyone know the structure/format for a TShortCut or how to easily use the THotKey control to register system HotKeys. Please I really need some help, I''ve been stuck on this for a while now, and none of my searches have gotten me anywhere.

Share this post

Link to post
Share on other sites
Okay... after running a battery of tests on TShortCut it appears the 3 high order bits of the upper byte map to CTRL, ALT, and SHIFT respectively (the rest are all zeros). The lower byte seems to be whatever the "hot" key is. So for CTRL+ALT+S you would get:


Now I just have to figure out how to quickly parse through that upper byte to assign the correct key sequence to the system hotkey. What would be my best approach? Should I use a mask or shift the bits or maybe just look at the total value and match it with specific cases (i.e. CTRL, CTRL+ALT, CTRL+SHIFT, CTRL+ALT+SHIFT, ALT, etc.)?

[edited by - Xorcist on March 25, 2002 3:31:26 PM]

Share this post

Link to post
Share on other sites
In case anyone is interested this is basically what I had to do to determine what modifiers keys where flagged by the high order byte of a TShortCut (in my case hot_Unhide.HotKey):

//Determine modifier keys

case Hi(hot_Unhide.HotKey) of
128: Modifier := MOD_ALT; //1

64: Modifier := MOD_CONTROL; //2

192: Modifier := MOD_ALT or MOD_CONTROL; //3

32: Modifier := MOD_SHIFT; //4

160: Modifier := MOD_ALT or MOD_SHIFT; //5

96: Modifier := MOD_CONTROL or MOD_SHIFT; //6

224: Modifier := MOD_ALT or MOD_CONTROL or MOD_SHIFT; //7

Modifier := 0;

The commented values to the far right are those of the actual modifier keys as assigned through the Windows unit. So even though TShorcut sees ALT as 128, it's value as used by RegisterHotKey should actually be 1. The low order byte doesn't need any changes as it directly represents the ASCII value of the terminating hotkey. So registering a system hotkey becomes as easy as:

if not RegisterHotkey(Handle, 1, Modifier, Lo(hot_Unhide.HotKey)) then begin
//Handle Error Case Here


[edited by - Xorcist on March 28, 2002 12:42:53 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!