整个系统响应,在handlemsg要做什么都可以type
  TForm1 = class(TForm)
...public
    procedure HandleMsg(var Msg:TMessage);message WM_HOTKEY;
procedure TForm1.FormCreate(Sender: TObject);
begin
      if RegisterHotKey(Handle,$1000,MOD_CONTROL,VK_RETURN)=true then
      begin
        showmessage('OK');
        //UnRegisterHotKey(Handle,$1000);
      end;
end;
procedure TForm1.HandleMsg(var Msg: TMessage);
begin
        Application.Terminate;
end;  
给分!! 

解决方案 »

  1.   

    错了!
    procedure TForm1.HandleMsg(var Msg: TMessage);
    begin
            ShowMessage('Hello');
            Application.BringToFront;//你在这里可以进行任何处理。调用函数把程序激活
    end;  
      

  2.   

    say():刚发现在自己的程序里面没法把自己调到最前面,好象这是windows的规定。
    我刚才用了一大群函数,没用!!
    最坏的打算,两个程序,一个监控接受热键,一个主程序,又监控的激活主程序就行了!
    procedure TForm1.HandleMsg(var Msg: TMessage);
    begin
            ShowMessage('Hello');
            Button1.Caption:='Hello';
            Application.BringToFront;
            SetWindowLong(Form1.Handle,GWL_EXSTYLE,GetWindowLong(Form1.Handle,GWL_EXSTyle) or WS_EX_TOPMOST);
            Form1.Show;
            Application.Restore;
            SetForeGroundWindow(Form1.Handle);
            //Application.Active:=True;
    end;
      

  3.   

    欢迎使用HotKey!HotKey的中文名字是“热键注册器”
    功能顾名思义,就是给你经常用的程序,文档,文件夹加上你自己定义的快捷键,就像Oicq那样一样,你只需要按一下你自己定义的热键,就可以运行你想要的东东了,呵呵!特点:1:最多可支持多达50个热键;
          2:用了Tray技术,你可以把HotKey放在任务栏里,然后就可以无所顾忌的         用你所注册的热键了;
          3:有记忆功能,你上次注册的热键这次依然有效(其实是把你所注册的热         键记录在文件里了C:\Action.dat和C:\HotKey.dat)使用方法:很简单,在左边选择你所要用的文件,文件夹,或程序(注意啊!可以只选文件夹的),然后点击“自定义热键”,使下面的文本框得到热键,然后你就可以用键盘定义热键了,最后点击“确定”,就可以了。删除更简单,选择你要删除的热键,然后点击“删除”。附注:1:这个程序是用Delphi5写的,如果你感兴趣,可以给我来信要源代码。
          2:如果要删除C:\Action.dat和C:\HotKey.dat两个文件,请一起删除。
          3:这是免费软件,如果你觉的好或不好,欢迎给我來信。我的Email:[email protected]呵呵,我前几天写的,如果你要,给我来信
    别害怕是病毒,我只给你代码,原理就是捕捉Wm_hotkey消息
      

  4.   

    ch81(missile):
        谢谢,让我试试再说!不过最好能在一个程序里实现
      

  5.   

    给我一个!!谢谢
    [email protected]
      

  6.   

    还是不成功呀,就是说能像FPE这类软件一样,接收热键弹出并置最前面,操作完后返回的功能。大家帮帮忙吧!唔该啦!!!
      

  7.   

    devecom(不再灌水) 
    say() 
    sundayboy
    程序已发出,忘了写主题了
    不过没有附件
    我把代码贴到信件里了
    如果有附件就不是我发的了
    望查收
      

  8.   

    { HotKeys控件源程序
      AMHotKeys version 1.0
      Copyright ?1999 by Alexander Meeder - AM Software  The idea for this component came from Arjen Broeze (e-mail: [email protected]) and I've used
      some of his code.  With this component you can set one or more "HotKey's" for your application. The hotkey-events
      will be triggered even if another program has the inputfocus. There are two kind of hotkey-events:
      * One overall hotkey-event with a special parameter (the HotKey-index)
      * One special hotkey-event for every enabled hotkey combination  TIP: When you use this component, always test the key-combination, because some key-combinations
      have a special meaning within windows and won't work.  TAMHotKey
      ---------
      property:
      * HotKeys (default property) is a THotKeys-collection, you can add new THotKeyItems at designtime
        using the collection editor
      event:
      * OnHotKeys is of type THotKeyEvent with one special Parameter: HotKeyIndex  THotKeys (see property of TAMHotKey)
      --------
      property:
      * HotKeys is a collection of type THotKeyItems (see below for more info about THotKeyItem)
      method:
      * Add, adds a new THotKeyItem to the collection  THotKeyItem
      -----------
      property:
      * Enabled (default false) is of type boolean and uses to en-/disable then hotkey
      * Modifiers (default none) is of type TModifiers and can be a combination of the Shift, Control, Alt and Win keys
      * VirtKey (default vkNone) is of type TVirtKey the actual hotkey (in combination with the modifier(s))
      event:
      * OnHotKey is of type TNotifyEvent and only triggered when there is code assigned to is and when
        the key-combination is Enabled  if you have suggestions and/or problems please mail me at: [email protected]
    }unit AMHotKey;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
      TAMHotKeys = class;  TWMHotKey = record
        Msg: Cardinal;
        idHotKey: Word;
        Modifiers: Integer;
        VirtKey : Integer;
      end;  TModifier = (modShift, modControl, modAlt, modWin);
      TModifiers = set of TModifier;  TVirtKey = (vkNone, vkCancel, vkBack, vkTab, vkClear, vkReturn, vkPause, vkCapital, vkEscape,
                  vkSpace, vkPrior, vkNext, vkEnd, vkHome, vkLeft, vkUp, vkRight, vkDown,
                  vkSelect, vkExecute, vkSnapshot, vkInsert, vkDelete, vkHelp,
                  vk0, vk1, vk2, vk3, vk4, vk5, vk6, vk7, vk8, vk9,
                  vkA, vkB, vkC, vkD, vkE, vkF, vkG, vkH, vkI, vkJ, vkK, vkL, vkM,
                  vkN, vkO, vkP, vkQ, vkR, vkS, vkT, vkU, vkV, vkW, vkX, vkY, vkZ,
                  vkNumpad0, vkNumpad1, vkNumpad2, vkNumpad3, vkNumpad4,
                  vkNumpad5, vkNumpad6, vkNumpad7, vkNumpad8, vkNumpad9,
                  vkMultiply, vkAdd, vkSeparator, vkSubtract, vkDecimal, vkDivide,
                  vkF1, vkF2, vkF3, vkF4, vkF5, vkF6, vkF7, vkF8, vkF9, vkF10, vkF11, vkF12,
                  vkF13, vkF14, vkF15, vkF16, vkF17, vkF18, vkF19, vkF20, vkF21, vkF22, vkF23, vkF24,
                  vkNumlock, vkScroll, vkApps);  THotKeyEvent = procedure(Sender: TObject; HotKeyIndex: Word) of object;  THotKeyItem = class(TCollectionItem)
      private
        FEnabled   : boolean;
        FModifiers : TModifiers;
        FRegistered: Boolean;
        FVirtKey   : TVirtKey;
        FHotKey: TNotifyEvent;    procedure SetEnabled(Value: Boolean);
        procedure SetModifiers(Value: TModifiers);
        procedure SetVirtKey(Value: TVirtkey);    procedure RegisterHK;
        procedure UnregisterHK;
      protected
        function GetDisplayName: string; override;
      public
        constructor Create(Collection: TCollection); override;
        procedure Assign(Source: TPersistent); override;    property Registered: Boolean read FRegistered Default false;
      published
        property Enabled: boolean read FEnabled write SetEnabled Default false;
        property Modifiers: TModifiers read FModifiers write SetModifiers;
        property VirtKey: TVirtKey read FVirtKey write SetVirtKey default vkNone;
        property OnHotKey: TNotifyEvent read FHotKey write FHotKey;
      end;  THotKeys = class(TCollection)
      private
        FAMHotKeys: TAMHotKeys;
        function GetItem(Index: Integer): THotKeyItem;
        procedure SetItem(Index: Integer; Value: THotKeyItem);
      protected
        function GetOwner: TPersistent; override;
      public
        constructor Create(AMHotKeys: TAMHotKeys);
        function Add: THotKeyItem;
        property HotKeys[Index: Integer]: THotKeyItem read GetItem write SetItem; default;
      end;  TAMHotKeys = class(TComponent)
      private
        FHotKeys: THotKeys;
        FHotKeyEvents: THotKeyEvent;    OldWndProc : TFarProc;
        NewWndProc : Pointer;    procedure SetHotKeys(Value: THotKeys);
        procedure HookParent;
        procedure UnhookParent;
        procedure HookWndProc(var Message: TMessage);
      protected
        procedure Loaded; override;
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
      published
        property HotKeys: THotKeys read FHotKeys write SetHotKeys;
        property OnHotKeys: THotKeyEvent read FHotKeyEvents write FHotKeyEvents;
      end;procedure Register;implementationvar
      VirtKeys : array[TVirtKey] of UInt =
                 ($00, $03, $08, $09, $0C, $0D, $13, $14, $1B,
                  $20, $21, $22, $23, $24, $25, $26, $27, $28,
                  $29, $2B, $2C, $2D, $2E, $2F,
                  $30, $31, $32, $33, $34, $35, $36, $37, $38, $39,
                  $41, $42, $43, $44, $45, $46, $47, $48, $49, $4A,
                  $4B, $4C, $4D, $4E, $4F, $50, $51, $52, $53, $54,
                  $55, $56, $57, $58, $59, $5A,
                  $60, $61, $62, $63, $64, $65, $66, $67, $68, $69,
                  $6A, $6B, $6C, $6D, $6E, $6F,
                  $70, $71, $72, $73, $74, $75, $76, $77, $78, $79, $7A, $7B,
                  $7C, $7D, $7E, $7F, $80, $81, $82, $83, $84, $85, $86, $87,
                  $90, $91, $5D);  VirtKeyStr : array[TVirtKey] of string =
                 ('None', 'Cancel', 'Back', 'Tab', 'Clear', 'Return', 'Pause', 'Capital', 'Escape',
                  'Space', 'Prior', 'Next', 'End', 'Home', 'Left', 'Up', 'Right', 'Down',
                  'Select', 'Execute', 'Snapshot', 'Insert', 'Delete', 'Help',
                  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
                  'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
                  'Numpad0', 'Numpad1', 'Numpad2', 'Numpad3', 'Numpad4',
                  'Numpad5', 'Numpad6', 'Numpad7', 'Numpad8', 'Numpad9',
                  'Multiply', 'Add', 'Separator', 'Subtract', 'Decimal', 'Divide',
                  'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12',
                  'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F20', 'F21', 'F22', 'F23', 'F24',
                  'Numlock', 'Scroll', 'Apps');// TAMHotKeys implementation
    procedure TAMHotKeys.SetHotKeys(Value: THotKeys);
    begin
      FHotKeys.Assign(Value);
    end;procedure TAMHotKeys.HookParent;
    begin
      if not (csDesigning in ComponentState) then
      begin
        if (Owner as TForm) = nil then exit;    OldWndProc := TFarProc(GetWindowLong((Owner as TWinControl).Handle, GWL_WNDPROC));
        NewWndProc := MakeObjectInstance(HookWndProc);
        SetWindowLong((Owner as TWinControl).Handle, GWL_WNDPROC, LongInt(NewWndProc));
      end;
    end;procedure TAMHotKeys.UnhookParent;
    begin
      if ((Owner as TForm) <> nil) and Assigned(OldWndProc) then
         SetWindowLong((Owner as TWinControl).Handle, GWL_WNDPROC, LongInt(OldWndProc));
      if Assigned(NewWndProc) then
         FreeObjectInstance(NewWndProc);  NewWndProc := nil;
      OldWndProc := nil;
    end;procedure TAMHotKeys.HookWndProc(var Message: TMessage);
    var
      I: integer;
    begin
      if (Owner as TWinControl) = nil then exit;  with Message do
      begin
        Result := CallWindowProc(OldWndProc, (Owner as TWinControl).Handle, Msg, wParam, lParam);    // if the message is a WM_HOTKEY-message then its for us
        if Msg = WM_HOTKEY then
        begin
          with TWMHotKey(Message) do
          begin
            if Assigned(HotKeys[idHotKey].FHotKey) then HotKeys[idHotKey].FHotKey(Self);
            if Assigned(FHotKeyEvents) then FHotKeyEvents(Self, idHotKey);
          end;    // if the owner (a TForm-object) will be destroyed then we have to 'unregister' all
        // enabled HotKey-combinations by disabling them
        if Msg = WM_DESTROY then
          for I := 0 to HotKeys.Count - 1 do
            HotKeys[I].Enabled := false;
        end
      end;
    end;procedure TAMHotKeys.Loaded;
    var
      I: integer;
    begin
      if not (csDesigning in ComponentState) then
        for I := 0 to HotKeys.Count - 1 do
          if HotKeys[I].Enabled then HotKeys[I].RegisterHK;
    end;constructor TAMHotKeys.Create(AOwner: TComponent);
    var
      I: integer;
    begin
      for I := 0 to AOwner.ComponentCount - 1 do
        if AOwner.Components[I] is TAMHotKeys then
          raise Exception.Create('No more than one TAMHotKeys-component on a form');  if (AOwner =  nil) or not (AOwner is TForm) then
        raise Exception.Create('The owner of TAMHotKeys must be a form');  inherited Create(AOwner);
      FHotKeys := THotKeys.Create(Self);  NewWndProc := nil;
      OldWndProc := nil;
      HookParent;
    end;destructor TAMHotKeys.Destroy;
    begin
      FHotKeys.Free;
      UnhookParent;
      inherited Destroy;
    end;// THotKeys implementation
    function THotKeys.GetItem(Index: Integer): THotKeyItem;
    begin
      Result := THotKeyItem(inherited GetItem(Index));
    end;procedure THotKeys.SetItem(Index: Integer; Value: THotKeyItem);
    begin
      inherited SetItem(Index, Value);
    end;function THotKeys.GetOwner: TPersistent;
    begin
      Result := FAMHotKeys;
    end;function THotKeys.Add: THotKeyItem;
    begin
      Result := THotKeyItem(inherited Add);
    end;constructor THotKeys.Create(AMHotKeys: TAMHotKeys);
    begin
      inherited Create(THotKeyItem);
      FAMHotKeys := AMHotKeys;
    end;// THotKeyItem implementation
    procedure THotKeyItem.SetEnabled(Value: boolean);
    begin
      if (Value <> FEnabled) then
      begin
        FEnabled := Value;    if not (csDesigning in TAMHotKeys(THotKeys(GetOwner).GetOwner).ComponentState) then
          if FEnabled then
            RegisterHK
          else
            UnregisterHK;
      end;
    end;procedure THotKeyItem.SetModifiers(Value: TModifiers);
    begin
      if Value <> FModifiers then
      begin
        FModifiers := Value;
      end;
    end;procedure THotKeyItem.SetVirtKey(Value: TVirtKey);
    begin
      if Value <> FVirtKey then
      begin
        FVirtKey := Value;
        if Value = vkNone then Enabled := False;
      end;
    end;function THotKeyItem.GetDisplayName: string;
    begin
      Result := '';
      if modShift    in Modifiers then Result := Result + 'Shift';
      if modControl  in Modifiers then Result := Result + 'Control';
      if modAlt      in Modifiers then Result := Result + 'Alt';
      if modWin      in Modifiers then Result := Result + 'Win';
      if Result = '' then
        Result := VirtKeyStr[VirtKey]
      else
        Result := Result + '_' + VirtKeyStr[VirtKey];  if Result = '' then Result := inherited GetDisplayName;
    end;procedure THotKeyItem.Assign(Source: TPersistent);
    begin
      if Source is THotKeyItem then
      begin
        Enabled := THotKeyItem(Source).Enabled;
        Modifiers := THotKeyItem(Source).Modifiers;
        VirtKey := THotKeyItem(Source).VirtKey;
        Exit;
      end;
      inherited Assign(Source);
    end;procedure THotKeyItem.RegisterHK;  function ModToFlag(Modifiers : TModifiers): UInt;
      begin
        Result := 0;
        if modShift    in Modifiers then Result := Result or MOD_SHIFT;
        if modControl  in Modifiers then Result := Result or MOD_CONTROL;
        if modAlt      in Modifiers then Result := Result or MOD_ALT;
        if modWin      in Modifiers then Result := Result or MOD_WIN;
      end;begin
      FRegistered := False;
      if (VirtKey <> vkNone) then
        FRegistered := RegisterHotKey((TAMHotKeys(THotKeys(GetOwner).GetOwner).Owner as TWinControl).Handle,
                                       Index, ModToFlag(Modifiers), VirtKeys[VirtKey]);
    end;procedure THotKeyItem.UnregisterHK;
    begin
      if FRegistered then
        FRegistered := not UnregisterHotKey((TAMHotKeys(THotKeys(GetOwner).GetOwner).Owner as TWinControl).Handle, Index);
    end;constructor THotKeyItem.Create(Collection: TCollection);
    begin
      inherited Create(Collection);
      FEnabled := False;
      FRegistered := False;
      FVirtKey := vkNone;
    end;procedure Register;
    begin
      RegisterComponents('AM Software', [TAMHotKeys]);
    end;end.
      

  9.   

    To say():
    我是一个更菜的鸟,我也正为这个问题而烦呢?你能把主要代码告诉我吗?我是学C++Builder的,但是Delphi的代码我也可以仔细研究的!!!期待中.....E-mail:[email protected]多谢!!!!