D
D
DeeUs2021-04-14 10:09:20
Delphi
DeeUs, 2021-04-14 10:09:20

How to implement keyboard shortcuts only in the active form?

Hello!
How to make keyboard shortcuts in the program, but so that they only work when the form is active? (The program starts in the tray by default).
I added the ctrl+z combination via RegisterHotKey, but there is a problem - when the program is running ctrl+z does not work in other programs.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hemul GM, 2021-04-14
@DeeUs

You don't need to register such "ctrl+z" combinations in the system.
In order for the form to process combinations, use the simple event OnKeyUp (or, if necessary, OnKeyDown). In order for the combination to be processed first of all by the form, and not by the control in focus, then set the form propertyKeyPreview = True

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
  if [ssCtrl] = Shift then
    case Key of
      vkZ: //Ctrl+Z pressed
        ;
    end;
end;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question