The RegisterHotKey function defines a hot key for the current thread. BOOL RegisterHotKey(    HWND hWnd, // window to receive hot-key notification
    int id, // identifier of hot key
    UINT fsModifiers, // key-modifier flags
    UINT vk  // virtual-key code
   );
 ParametershWndIdentifies the window that will receive WM_HOTKEY messages generated by the hot key. If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop. idSpecifies the identifier of the hot key. No other hot key in the calling thread should have the same identifier. An application must specify a value in the range 0x0000 through 0xBFFF. A shared dynamic-link library (DLL) must specify a value in the range 0xC000 through 0xFFFF (the range returned by the GlobalAddAtom function). To avoid conflicts with hot-key identifiers defined by other shared DLLs, a DLL should use the GlobalAddAtom function to obtain the hot-key identifier. fsModifiersSpecifies keys that must be pressed in combination with the key specified by the nVirtKey parameter in order to generate the WM_HOTKEY message. The fsModifiers parameter can be a combination of the following values: Value Meaning
MOD_ALT Either ALT key must be held down.
MOD_CONTROL Either CTRL key must be held down.
MOD_SHIFT Either SHIFT key must be held down.
 vkSpecifies the virtual-key code of the hot key.  Return ValuesIf the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. ResWhen a key is pressed, the system looks for a match against all thread hot keys. Upon finding a match, the system posts the WM_HOTKEY message to the message queue of the thread that registered the hot key. This message is posted to the beginning of the queue so it is removed by the next iteration of the message loop. 
This function cannot associate a hot key with a window created by another thread. 
RegisterHotKey fails if the keystrokes specified for the hot key have already been registered by another hot key. If the window identified by the hWnd parameter already registered a hot key with the same identifier as that specified by the id parameter, the new values for the fsModifiers and vk parameters replace the previously specified values for these parameters.
The UnregisterHotKey function frees a hot key previously registered by the calling thread. BOOL UnregisterHotKey(    HWND hWnd, // window associated with hot key
    int id  // identifier of hot key
   );
 ParametershWndIdentifies the window associated with the hot key to be freed. This parameter should be NULL if the hot key is not associated with a window. idSpecifies the identifier of the hot key to be freed.  Return ValuesIf the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

解决方案 »

  1.   

    举个例子吧!
    比如在程序中,你用 Ctrl + F1 来调用频幕保护,Follow me!!在FORM Create 事件中,添加:
    HotKeyId := GlobalAddAtom(‘MyHotKey’) - $C000;
    {注: HotKeyId的合法取之范围是0x0000到0xBFFF之间, GlobalAddAtom函数得到的值在0xC000到0xFFFF之间,所以减掉0xC000来满足调用要求。}
    RegisterHotKey(Handle, hotkeyid, MOD_CONTROL, VK_F1);原理:一旦热键设置成功,在程序应用过程中如果有相应的键被按下,Windows系统都会给你的应
    用程序发送一个消息WM_HOTKEY,不管你的应用程序是否为当前活动的。其中WM_HOTKEY消
    息的格式为:  idHotKey = (int) wParam; // 该参数在设置系统级的热键有用,一般不予使用
    fuModifiers = (UINT) LOWORD(lParam);  //热键的辅助按键
    uVirtKey = (UINT) HIWORD(lParam); //热键的键值
    在程序中添加:
    procedure Tfmain.HotKeyDown(var Msg: Tmessage); 
    begin 
    if (Msg.LparamLo = MOD_control) AND Msg.LParamHi = VK_F1 then 
         // 假设热键为control+F1 
    begin
    ........................ 
    end;  
    end;
    在Form Close 事件中,添加:
    UnRegisterHotKey(handle, HotKeyId); //注销HotKey, 释放资源。
      

  2.   

    谢谢两位高手的指点!
    请问budded(budded) :
    procedure Tfmain.HotKeyDown(var Msg: Tmessage); 如何添加上去?
    HotKeyId := GlobalAddAtom(‘MyHotKey’) - $C000;中的MyHotKey在应用时是不是要输入相应的值?
    我照你所说的去做没有成功!