How can I prevent the tab key from navigating away from a FireMonkey button ?
If the user presses TAB key, I want the button to remain as the active control
I have tried various code in OnKeyDown and OnKeyUp but cant get it to work
Any ideas ?
Scott
davidn
(Dave Nottage)
2
One way is to override the KeyDown method of the form, and check the focused control, like this:
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Edit, FMX.Controls.Presentation, FMX.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
private
{ Private declarations }
public
procedure KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState); override;
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.KeyDown(var Key: Word; var KeyChar: System.WideChar; Shift: TShiftState);
begin
if (Key = vkTab) and (Focused <> nil) and (Focused.GetObject = Button1) then
begin
Key := 0;
KeyChar := #0;
end
else
inherited;
end;
end.
2 Likes