Pb中idle事件的用处及idle(N)函数的用法:

本文详细介绍了Idle函数的功能和用法,该函数可在用户一段时间无活动后触发应用的Idle事件,实现如屏幕保护、自动退出等功能,增强应用安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

功能该函数在用户每次活动(例如,按键盘、移动鼠标等)后重置定时器,n秒后触发应用对象的Idle事件。
  语法Idle ( n )
  参数n:指定空闲时间间隔,以秒为单位。该参数的值设置为0时,停止空闲检测,不再触发应用对象的Idle事件返回值Integer。函数执行成功时返回1,此时启动定时器。如果不能启动定时器或定时器未启动而n的值指定为0时,函数返回-1。如果任何参数的值为NULL,Idle()函数返回NULL。用法利用Idle()函数,应用 程序 可以构造自己的屏幕保护程序,避免安全数据的泄露。当使用Idle()函数已经启动了定时器后,如果再次以非0参数调用Idle()函数,那么该函数重设时间间隔,但并不启动新的定时器。Idle()函数启动定时器后,如果在指定的时间间隔(从用户最近一次操作算起)内没有操作应用程序,那么就触发应用对象的Idle事件,在这个事件中可以编写关闭窗口、退出数据库登录等一系列 代码 ,然后使用Restart()函数重新启动应用程序,起到保密的目的。发生下述任何情况时,系统自动重置定时器(即重新开始计时):n
用户在该应用程序的任何窗口内移动鼠标或单击鼠标(双击鼠标时首先触发单击事件)n 在该应用程序的某个窗口是当前窗口时用户按下了任意一个或多个键n 在该应用程序的窗口最小化时,用户在该应用的图标上单击鼠标或移动鼠标n 在该应用程序的窗口最小化并且该应用程序是当前应用程序(应用名称被加亮显示)时,用户按了任何按键n 可视数据窗口检索数据时引起的编辑控件(指漂浮在数据窗口当前行/列上的编辑控件)
  
  Idle event:
  Description  
  Occurs when the Idle function has been called in an application object script and the specified number of seconds have elapsed with no mouse or keyboard activity.
  Event ID  
  Event ID Objects
  None Application
  Arguments  
  None
  Return value  
  None (do not use a RETURN statement)
  
  For examples:
  This statement in an application script causes the Idle event to be triggered after 300 seconds of inactivity:
  Idle(300)
  In the Idle event itself, this statement closes the application:
  HALT CLOSE
  
  Idle PowerScript function:
  Description  
  Sets a timer so that PowerBuilder triggers an Application Idle event when there has been no user activity for a specified number of seconds.
  Syntax  
  Idle ( n )
  Argument Description
  n The number of seconds of user inactivity allowed before PowerBuilder triggers an Application Idle event. A value of 0 terminates Idle detection.
  Return value  
  Integer. Returns 1 if it starts the timer, and -1 if it cannot start the timer or n is 0 and the timer has not been started. Note that when the timer has been started and you change n, Idle does not start a new timer; it resets the current timer interval
to the new number of seconds. If n is NULL, Idle returns NULL. The return value is usually not used.
  Usage  
  Use Idle to shut off or restart an application when there is no user activity. This is often done for security reasons.
  
  Idle starts a timer after each user activity (such as, a keystroke or a mouse click), and after n seconds of inactivity it triggers an Idle event. The Idle event script for an application typically closes some windows, logs off the database, and exits the
application or calls the Restart function.
  The timer is reset when any of the following activities occur:  
  
  <1>A mouse movement or mouse click in any window of the application
  <2>Any keyboard activity when a window of the PowerBuilder application is current
  <3>A mouse click or any mouse movement over the icon when a PowerBuilder application is minimized
  <4>Any keyboard activity when the PowerBuilder application is minimized and is current (its name is highlighted)
  <5>Any retrieval on a visible DataWindow that causes the edit control to be painted  
  
  Tip To capture movement, write script in the MouseMove or Key events of the window or sheet. (Keyboard activity does not trigger MouseMove events.) Disable the DataWindow control and tab ordering during iterative retrieves so the Idle timer is not reset.
  his statement sends an Idle event after five minutes of inactivity:
  
  Idle(300)
  
  This statement turns off idle detection:
  
  Idle(0)
  
  This example shows how to use the Idle event to stop the application and restart it after two minutes of inactivity. This is often used for computers that provide information in a public place.
  Include this statement in the script for the application's Open event:
  
  Idle(120) // Sends an Idle event after 2 minutes.
  
  Include these statements in the script for the application's Idle event to terminate the application and then restart it:
  
  // Statements to set the database to the desired
  
  // state
  ...
  Restart() // Restarts the application
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值