zoukankan      html  css  js  c++  java
  • Firemonkey里触发home按键被按下的事件

    吾八哥我最近在使用Delphi里的Firemonkey平台写一个叫“由由密码管家”的APP工具,是跨多平台的,如ios/android/windows/macOs。由于是用于密码管理的,那么在手机里操作会很频繁的被按下home键而切换到后台的,所以希望程序被按下home键的时候隐藏到后台就自动锁定程序,再激活APP的时候要求重新输入密码才可以操作。那么问题来了,在Firemonkey里面如何捕获按下home键的事件呢?网上搜索各种资料,终于找到了答案,这里分享出来具体的解决方法:

    function TMaster.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
    begin
      case AAppEvent of
        TApplicationEvent.FinishedLaunching:
          ;
        TApplicationEvent.BecameActive:
          ;
        TApplicationEvent.WillBecomeInactive:
          begin
            if not Assigned(LoginFrame) then
              ShowFrame(TLoginFrame, Master, False);
            LoginFrame.BringToFront;
          end;
        TApplicationEvent.EnteredBackground:
          ;
        TApplicationEvent.WillBecomeForeground:
          ;
        TApplicationEvent.WillTerminate:
          ;
        TApplicationEvent.LowMemory:
          ;
        TApplicationEvent.TimeChange:
          ;
        TApplicationEvent.OpenURL:
          ;
      end;
      Result := True;
    end;

    当然,在使用前需要在 onCreate 中获取消息接口

    使用IFMXApplicationEventService接口里的SetApplicationEventHandler方法将上述事件方法作为参数进行调用即可实现,HandleAppEvent方法里会触发各种程序相关的事件通知。代码如下:

    var
      SvcEvents: IFMXApplicationEventService;
    begin
      if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(SvcEvents)) then
      begin
        SvcEvents.SetApplicationEventHandler(HandleAppEvent);
      end;
    end;
  • 相关阅读:
    如何调试webservice接口是否正常
    备份数据库表
    【web】sqli-labs学习
    【web】php文件包含(利用phpinfo)
    【二进制】【WP】MOCTF逆向题解
    【web】BUUCTF-web刷题记录
    【WP】【web】中学生CTF | web部分wp
    【密码学】AES简单学习
    【密码学】CBC反转字节攻击
    【WP】攻防世界-杂项-Misc
  • 原文地址:https://www.cnblogs.com/westsoft/p/8413811.html
Copyright © 2011-2022 走看看