Delphi 使用热键,即使窗口隐藏在托盘中。在德尔福有可能吗?

Delphi 使用热键,即使窗口隐藏在托盘中。在德尔福有可能吗?,delphi,hide,hotkeys,tray,Delphi,Hide,Hotkeys,Tray,我需要在系统托盘中隐藏一个表单,但同时我想使用热键,例如“ctrl+3”从tEdit获取隐藏表单上的文本,并将其插入Firefox SendText(edit1.text);//用这种方法'。我知道如何插入文本,但我对热键/任何建议一无所知?非常感谢。在下面插入文本的代码 procedure SendText(const Value: WideString); var I: Integer; S: WideString; TI: TInput; KI: TKeybdInput;

我需要在系统托盘中隐藏一个表单,但同时我想使用热键,例如“ctrl+3”从tEdit获取隐藏表单上的文本,并将其插入Firefox SendText(edit1.text);//用这种方法'。我知道如何插入文本,但我对热键/任何建议一无所知?非常感谢。在下面插入文本的代码

procedure SendText(const Value: WideString);
var
  I: Integer;
  S: WideString;
  TI: TInput;
  KI: TKeybdInput;
const
  KEYEVENTF_UNICODE = $0004;
begin
  S := WideUpperCase(Value); 
  TI.Itype := INPUT_KEYBOARD;
  for I := 1 to Length(S) do
  begin
    KI.wVk := 0;
    KI.dwFlags := KEYEVENTF_UNICODE;
    KI.wScan := Ord(S[I]);
    TI.ki := KI;
    SendInput(1, TI, SizeOf(TI));
  end;
end;

要注册系统范围的热键,必须使用和函数

检查一下这个样品

type
  TForm125 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    HotKey1 : Integer;
    procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
  public

  end;

var
  Form125: TForm125;

implementation

{$R *.dfm}


procedure TForm125.FormCreate(Sender: TObject);
begin
  HotKey1 := GlobalAddAtom('MyAppHotkey1');//create a unique value for identify the hotkey
  if not RegisterHotKey(Handle, HotKey1, MOD_CONTROL, VK_F1) then //register the hotkey CTRL + F1
   ShowMessage('Sorry can not register the hotkey');
end;

procedure TForm125.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey(Handle, HotKey1);//unregister the hotkey
  GlobalDeleteAtom(HotKey1);//remove the atom
end;

procedure TForm125.WMHotKey(var Msg: TWMHotKey);
begin
  if Msg.HotKey = HotKey1 then
    ShowMessage('Hello'); // do your stuff
end;

只需小心选择的按键组合,因为它可以在其他应用程序内部使用。例如,Firefox使用组合Ctrl键切换选项卡。

请注意,系统范围的热键可能与应用程序热键冲突。例如,ctrl+3会使我的应用程序中的一个热键停止工作。为用户提供自定义系统范围热键的选项。