title: Cannot register multiple global hotkeys
body: <p>I have been trying to register 3 hotkeys.
  I followed <a href="http://209.85.229.132/search?q=cache:SxqcrRMN6zAJ:www.delphi3000.com/articles/article_3529.asp+GetShortCutKey+GetShortCutModifier&amp;cd=3&amp;hl=en&amp;ct=clnk&amp;gl=de&amp;client=firefox-a" rel="nofollow noreferrer">this</a> example (or <a href="http://www.delphi3000.com/articles/article_3529.asp" rel="nofollow noreferrer">this</a>).</p>
  
  <p>The code is working IF I register a single hotkey.
  However, if I try to register 3 hotkeys, only the last registered one is working:</p>
  
  <pre><code>procedure TFrmSettings.FormCreate;
  begin
   atomN:= GlobalAddAtom(pchar('atomN'));    
   atomT:= GlobalAddAtom(pchar('atomT'));
   atomH:= GlobalAddAtom(pchar('atomH'));
  end;
  
  
  procedure TFrmSettings.test1;
  begin
   RegisterHotShortCut(Handle, atomN, hotN.HotKey);        // first registered 
   RegisterHotShortCut(Handle, atomH, hotH.HotKey);        // second registered 
   RegisterHotShortCut(Handle, atomT, hotT.HotKey);        // third - only this works
  end;
  </code></pre>
  
  <p>RegisterHotShortCut is declared in the web page above mentioned.</p>
  
  <pre><code>function RegisterHotShortCut(const h:THandle; const Atom: integer; const ShortCut: TShortCut): Boolean;
  VAR
    key : Word;
    Shift: TShiftState;
  begin
    Windows.UnregisterHotKey(h, Atom);                                                    
    ShortCutToKey(ShortCut, key, shift);
    Result:= RegisterHotKey(h, Atom, ShiftState2Modifier(Shift), key);
  end;
  </code></pre>
  
  <p>If in the code above, I comment the last line, then the previous hotkey (hotH) is working. This means that I declared everything right but the last hotkey takes control over (unregisters) the others.</p>
  
  <p>Or saying it in other way, pressing the key combination for the for first registered shortcuts do not make the program to enter the  <code>TFrmSettings.HotyKeyMsg(VAR msg: TMessage)</code> procedure.</p>
  
  <p>Any hints?
  Thanks.</p>
  
  <hr>
  
  <p>Edit1:</p>
  
  <ol>
  <li><p>There are simple snippets that seems to work for other but I really need to let the user to change the shortcut so I need the ShortCutToKey procedure.</p></li>
  <li><p>I should declare an atom for each global shortcut. Right?</p></li>
  </ol>
  
  <hr>
  
  <p>Edit2:
  <strong>SOLVED</strong>
  The above code fails ONLY if I use the "GlobalAddAtom" function. If instead of atoms I use just numbers 1, 2 and 3, the code works. If I use 4,5,6, the code fails again.
  Problem (semi) solved.</p>