Recent

Author Topic: Fire the CTRL-F9 button everywhere in windows 10.  (Read 954 times)

pascalbythree

  • Sr. Member
  • ****
  • Posts: 256
Fire the CTRL-F9 button everywhere in windows 10.
« on: March 09, 2023, 06:47:14 pm »

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
  2.   );
  3. begin
  4.    if (Shift = [ssCtrl]) AND (Key = 120) then memo1.Lines.Append('Ctrl F9');
  5. end;

Like this it got to work to receive the CTRL-F9 key when pressed on the form.

Does anybody know what to change to fire the code from the CTRL-F9 key, everywhere in windows 10 ? Even though the form is not focused ?

Greets, Wouter van Wegen

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Fire the CTRL-F9 button everywhere in windows 10.
« Reply #1 on: March 09, 2023, 06:49:47 pm »
Especially Lazarus users are going to thank you for "stealing" Ctrl+F9  O:-)

Bart

pascalbythree

  • Sr. Member
  • ****
  • Posts: 256
Re: Fire the CTRL-F9 button everywhere in windows 10.
« Reply #2 on: March 09, 2023, 07:02:20 pm »
CTRL-F10 will also do.

Just as it responds everywhere in windows when application not focused.
« Last Edit: March 09, 2023, 07:04:03 pm by pascalbythree »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9911
  • Debugger - SynEdit - and more
    • wiki
Re: Fire the CTRL-F9 button everywhere in windows 10.
« Reply #3 on: March 09, 2023, 07:31:59 pm »
google: msdn global key hook

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11459
  • FPC developer.
Re: Fire the CTRL-F9 button everywhere in windows 10.
« Reply #4 on: March 09, 2023, 07:36:10 pm »
In Delphi this is done via applicationevents.shortcut

Code: [Select]
procedure TRootMain.ApplicationEvents1ShortCut(var Msg: TWMKey;
  var Handled: Boolean);

var
 RawMessage: TMessage;
 fkey,shift : integer;
begin
 if not assigned(basehandling) or not allowkeys then
    exit;
 // Kijk in de raw message welke message er gestuurd is.

{  if Msg.Msg = WM_KEYDOWN then
 begin}
   // Debug: Log de tijd in een memo op het main form om te zien of het werkt.
   // Memo1.Lines.Insert(0, DateTimeToStr(Now));
   // Gebruik een 'normale' TMessage omdat dat makkelijker is.

   RawMessage:= TMessage(Msg);

   // Die is namelijk eventueel te typecasten naar een speciaal daarvoor
   // gemaakt record. Je kunt natuurlijk ook rechtstreeks de WParam en LParam
   // van Msg gaan ontleden, maar dit is makkelijker.

   if (msg.CharCode >=VK_F1) and (msg.CharCode <=VK_F12) and not BaseHandling.canclose  then
     begin
       fkey:=msg.charcode-vk_f1;
       shift:=0;
       if HiByte(GetKeyState(VK_SHIFT))>0 then inc(shift,1);
       if (HiByte(GetKeyState(VK_MENU))>0) then inc(shift,2);
       if (HiByte(GetKeyState(VK_CONTROL))>0) then inc(shift,4);
       basehandling.keyevent(fkey,shift);
         //handled:=true;
     end
end;


paweld

  • Hero Member
  • *****
  • Posts: 1003
Re: Fire the CTRL-F9 button everywhere in windows 10.
« Reply #5 on: March 10, 2023, 07:54:12 am »
I use something like the one in the attachment
Best regards / Pozdrawiam
paweld

pascalbythree

  • Sr. Member
  • ****
  • Posts: 256
Re: Fire the CTRL-F9 button everywhere in windows 10.
« Reply #6 on: March 11, 2023, 10:13:16 am »
Thank you everybody, it got to work!

 

TinyPortal © 2005-2018