Let's say I have the following class,Code: Pascal [Select][+][-]TMainForm = class(TForm) InputText: TLabel; ResetButton: TButton; BackButton: TButton; NextButton: TButton; procedure FormCreate(Sender: TObject); procedure HandleKeyPress(Sender: TObject; var Key: char); end;HandleKeyPress updates the caption in InputText. How can I force HandleKeyPress to be called even if one of the 3 buttons are focused?
Focused or hovered? Controls have OnEnter and OnExit event handlers for focus changes. They also have OnMouseEnter and OnMouseLeave handlers for mouse hover.
Maybe:Code: Pascal [Select][+][-]unit Unit1; {$mode objfpc}{$H+} interface uses Classes, Forms, StdCtrls; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Label1: TLabel; procedure FormCreate(Sender: TObject); procedure KeyPress(Sender: TObject; var Key: char); virtual; end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin Button1.OnKeyPress := @KeyPress; Button2.OnKeyPress := @KeyPress; Button3.OnKeyPress := @KeyPress;end; procedure TForm1.KeyPress(Sender: TObject; var Key: char);var S: string;begin if Sender = Button1 then S := 'first button.' else if Sender = Button2 then S := 'second button.' else if Sender = Button3 then S := 'third button.' else Exit; Label1.Caption := Key + ' is pressed on the ' + S;end; end.
Isn't that what TForm.KeyPreView is for?Bart