From e5660cbc7abf79035c192eda360b552c144c9410 Mon Sep 17 00:00:00 2001 From: phil294 Date: Thu, 20 Jul 2023 11:02:00 +0200 Subject: [PATCH] Add built-in var `A_TimeIdle` --- docs/index.html | 6 +++--- src/run/display.cr | 3 +++ src/run/runner.cr | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/index.html b/docs/index.html index f5632ff..d368667 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1754,11 +1754,11 @@

User Idle Time

A_TimeIdle - # The number of milliseconds that have elapsed since the system last received keyboard, mouse, or other input. This is useful for determining whether the user is away. This variable will be blank unless the operating system is Windows 2000, XP, or beyond. Physical input from the user as well as artificial input generated by any program or script (such as the Send or MouseMove commands) will reset this value back to zero. Since this value tends to increase by increments of 10, do not check whether it is equal to another value. Instead, check whether it is greater or less than another value. For example: IfGreater, A_TimeIdle, 600000, MsgBox, The last keyboard or mouse activity was at least 10 minutes ago. + # The number of milliseconds that have elapsed since the system last received keyboard, mouse, or other input. This is useful for determining whether the user is away. This variable will be blank unless the operating system is Windows 2000, XP, or beyond. Physical input from the user as well as artificial input generated by any program or script (such as the Send or MouseMove commands) will reset this value back to zero. Since this value tends to increase by increments of 10, do not check whether it is equal to another value. Instead, check whether it is greater or less than another value. For example: IfGreater, A_TimeIdle, 600000, MsgBox, The last keyboard or mouse activity was at least 10 minutes ago. - A_TimeIdlePhysical - + A_TimeIdlePhysical +

# Same as above but ignores artificial input whenever the corresponding hook (keyboard or mouse) is installed. If neither hook is installed, this variable is equivalent to A_TimeIdle. If only one hook is present, only that one type of artificial input will be ignored. A_TimeIdlePhysical may be more useful than A_TimeIdle for determining whether the user is truly present.

diff --git a/src/run/display.cr b/src/run/display.cr index f1a2548..87ed2ed 100644 --- a/src/run/display.cr +++ b/src/run/display.cr @@ -101,8 +101,11 @@ module Run @unsuspend_listeners.each &.call end + getter last_event_received = Time.monotonic + # TODO: put keysym and char into key_event in callers? private def handle_event(key_event, keysym, char) + @last_event_received = Time.monotonic @key_listeners.each do |sub| spawn same_thread: true do sub.call(key_event, keysym, char, @is_paused) diff --git a/src/run/runner.cr b/src/run/runner.cr index 80ea71c..6d2786e 100644 --- a/src/run/runner.cr +++ b/src/run/runner.cr @@ -262,6 +262,7 @@ module Run when "a_computername" then `uname -n` when "a_issuspended" then @suspension ? "1" : "0" when "a_iscompiled" then @is_compiled ? "1" : "" + when "a_timeidle" then (Time.monotonic - display.last_event_received).total_milliseconds.round.to_i.to_s when "0" then (ARGV.size - (@script_file ? 1 : 0)).to_s else if i = var.to_i?