Search code examples
keysoftware-designlazarus

Lazarus IDE Do Action while pressing a key


I've wanted to know if i can link a special key (for example the "b" key) to a specific action?

For example when i press the button b that the software closes. Is this possible, if yes how do you do so?

Greetings


Solution

  • This is easy to do.

    • Create a new forms application.

    • Place a TButton on the form.

    • Set the button's caption to '&b'.

    • On the Events tab in the Object Inspector, click in the OnClick event and enter this code

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Close;
    end;
    
    • Compile and run the program.

    • Press the 'b' key and the form will close and the program will stop.