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

Started by
1 comment, last by Xorcist 22 years ago
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.
Advertisement
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:

110000001010011

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]
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    else      Modifier := 0;    end;   


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    end;    



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

This topic is closed to new replies.

Advertisement