如何用registerhotkey设置多个热键?
如可以用alt+f10,也能用单独的f10还能用其他的等。

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
        { Public declarations }
        id_F10, id_Alt_F10: Integer;
        procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.WMHotKey (var Msg : TWMHotKey);
    begin
      if Msg.HotKey = id_F10 then begin
        ShowMessage('F10');
      end else
      if Msg.HotKey = id_Alt_F10 then begin
        ShowMessage('Alt+F10');
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      if GlobalFindAtom('MyHotkey_F10') = 0 then begin
        id_F10 := GlobalAddAtom('MyHotkey_F10');
        RegisterHotKey(Handle, id_F10, 0, VK_F10);
      end;
      if GlobalFindAtom('MyHotkey_Alt_F10') = 0 then begin
        id_Alt_F10 := GlobalAddAtom('MyHotkey_Alt_F10');
        RegisterHotKey(Handle, id_Alt_F10, MOD_ALT, VK_F10);
      end;
    end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      UnRegisterHotKey(Handle,id_F10);
      GlobalDeleteAtom(id_F10);
      UnRegisterHotKey(Handle,id_Alt_F10);
      GlobalDeleteAtom(id_Alt_F10);
    end;end.