type TForm1 = class(TForm) .. private procedure OnHotKey(var Msg: TWMHotKey); message WM_HOTKEY; end; ... procedure TForm1.OnHotKey(var Msg: TWMHotKey); begin if .. then // <<----- Edit1.Text := '44' else if .. then // <<----- Edit1.Text := '55'; end; procedure TForm1.FormCreate(Sender: TObject); begin RegisterHotKey(Handle, Ord('U'), 0, Ord('U')); RegisterHotKey(Handle, Ord('P'), 0, Ord('P')); end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin UnregisterHotKey(Handle, Ord('U')); UnregisterHotKey(Handle, Ord('P')); end; 

What do I need to change so that when I click on U, it’s written 44 and when I press P, it’s written 55 ?

    2 answers 2

    Since you assign hotkeys indexes (the second parameter in RegisterHotKey ), you can compare directly with them:

     procedure TForm1.OnHotKey(var Msg: TWMHotKey); begin if Msg.HotKey = Ord('U') then Edit1.Text:='44'; if Msg.HotKey = Ord('R') then Edit1.Text:='55'; end; 

      Good day! You can handle keystrokes of certain keys on the form in the OnKeyDown event. There are 2 variables indicating the sent service (Shift .. etc) key and a simple one.