红鱼儿

Delphi D10.X安卓开发中按两次返回键退出系统的方法
unit fMain;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics,
  FMX.Dialogs, FMX.Objects;

type
  TForm5 = class(TForm)
    Text1: TText;
    procedure FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    vTiming: Cardinal; // 时间计数
  public
    { Public declarations }
  end;

var
  Form5: TForm5;

implementation

uses
  u_Toast;

const
  CIntervals: Integer = 1800;  //两次按键的间隔时间 毫秒

{$R *.fmx}

procedure TForm5.FormCreate(Sender: TObject);
begin
  vTiming := TThread.GetTickCount;
end;

procedure TForm5.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
  Shift: TShiftState);
begin
  //如果是按下返回键,并且大于间隔时间,则提示
  if (Key = vkHardwareBack) And (TThread.GetTickCount- vTiming> CIntervals) then
  begin
    Key := 0;
    vTiming := TThread.GetTickCount;
    Toast('再按一次退出');
  end;
end;

end.

原文地址:https://blog.csdn.net/tanqth/article/details/104713718

posted on 2022-04-25 23:06  红鱼儿  阅读(242)  评论(0编辑  收藏  举报