核心思路就是加入一个ApplicationEvents控件,控件在addtion栏中,delphi的内置控件。在其active事件中注册热键,在deactive控件中取消注册就可以了,其他的照旧。procedure TForm1.ApplicationEvents1Deactivate(Sender: TObject);vari: Integer;begin//注销热键for i := Low(HotKeyId) to High(HotKeyId) dobeginUnRegisterHotKey(handle, HotKeyId[i]);GlobalDeleteAtom(HotKeyId[i]);end;end;procedure TForm1.ApplicationEvents1Activate(Sender: TObject);vari: integer;begin//for i := Low(HotKeyId) to High(HotKeyId) doHotKeyId[i] := GlobalAddAtom(PChar(IntToStr(i))); //热键命名可随意RegisterHotKey(Handle, HotKeyId[11], MOD_CONTROL, 65); //PageUpRegisterHotKey(Handle, HotKeyId[12], MOD_CONTROL, 66); //PageUpRegisterHotKey(Handle, HotKeyId[13], MOD_CONTROL, 67); //PageUpRegisterHotKey(Handle, HotKeyId[14], MOD_CONTROL, 68); //PageUpRegisterHotKey(Handle, HotKeyId[15], MOD_CONTROL, 69); //PageUpRegisterHotKey(Handle, HotKeyId[16], MOD_CONTROL, 49); //PageUpRegisterHotKey(Handle, HotKeyId[17], MOD_CONTROL, 50); //PageUpRegisterHotKey(Handle, HotKeyId[5], 0, VK_PRIOR); //PageUpRegisterHotKey(Handle, HotKeyId[6], 0, VK_NEXT);RegisterHotKey(Handle, HotKeyId[7], 0, VK_escape); //PageDownRegisterHotKey(Handle, HotKeyId[2], MOD_CONTROL, VK_RETURN); //Ctrl+Enterend; |