title: action event outside delphi app
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4115429/how-can-i-handle-a-keyboard-shortcut-when-my-program-isnt-active">How can I handle a keyboard shortcut when my program isn&#39;t active?</a>  </p>
  </blockquote>
  
  
  
  <p>hello guys
  i need to make a delphi program that creates a short cut key that works outside the delphi app. for example: when i press ctrl+1 it pastes a certain text. When i press ctrl+2, another text, and so on. It really helps my work. I managed to make a delphi application that does that, but it only works inside that app. i want it to work in all windows applications as long as my app is open ( and minimized). Can anyone help me out? I'm pretty new at delphi, i'm trying to learn.</p>
  
  <p>I tried this code which someone recommended to me but it doesn't work. it does nothing. what did i do wrong?</p>
  
  <pre><code>unit Unit3;  
  
  interface  
  
  uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Clipbrd;  
  
  type  
    TForm17 = class(TForm)  
      procedure FormCreate(Sender: TObject);  
      procedure FormDestroy(Sender: TObject);  
    private  
      { Private declarations }  
      HotKey1 : Integer;  
      HotKey2 : Integer;  
      procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;  
    public  
      { Public declarations }  
    end;  
  
  
  var  
    Form17: TForm17;  
  
  implementation  
  
  {$R *.dfm}  
  
  { TForm17 }  
  
  procedure TForm17.FormCreate(Sender: TObject);  
  const  
    MOD_CONTROL = $0002;//0x0002  
  begin
    // Register Ctrl + 1 hotkey  
    HotKey1 := GlobalAddAtom('Hotkey1');  
    RegisterHotKey(Handle, HotKey1, MOD_CONTROL, Ord('1'));  
    // Register  Ctrl + 2 hotkey  
    HotKey2 := GlobalAddAtom('Hotkey2');  
    RegisterHotKey(Handle, HotKey2, MOD_CONTROL, Ord('2'));  
  end;  
  
  procedure TForm17.FormDestroy(Sender: TObject);  
  begin  
    //unregister the hotkeys  
    UnRegisterHotKey(Handle, HotKey1);  
    GlobalDeleteAtom(HotKey1);   
    UnRegisterHotKey(Handle, HotKey2);  
    GlobalDeleteAtom(HotKey2);  
  end;  
  
  procedure TForm17.WMHotKey(var Msg: TWMHotKey);   
  begin  
    if Msg.HotKey = HotKey1 then  
    begin  
      ShowMessage('Ctrl + 1 was pressed');  
       Clipboard.AsText := 'This is my own text!';  
  
    end  
    else   
    if Msg.HotKey = HotKey2 then  
    begin  
      ShowMessage('Ctrl + 2 was pressed');  
       Clipboard.AsText := 'This is my own text!';  
  
    end;  
  end;  
  
  end.     
  </code></pre>