Skip to content

Commit

Permalink
Add built-in var A_TimeIdle
Browse files Browse the repository at this point in the history
  • Loading branch information
phil294 committed Jul 20, 2023
1 parent 36cc806 commit e5660cb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1754,11 +1754,11 @@ <h4 class="calibre25">User Idle Time </h4>
<tbody class="calibre2">
<tr class="calibre3">
<td class="calibre4">A_TimeIdle</td>
<td class="calibre4 tbd"><a id="Variables.htm__TimeIdle" href="#Variables.htm__TimeIdle" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a> 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 <strong class="calibre14">any</strong> program or script (such as the <a href="#Send.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Send</a> or <a href="#MouseMove.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">MouseMove</a> 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. </td>
<td class="calibre4"><a id="Variables.htm__TimeIdle" href="#Variables.htm__TimeIdle" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a> 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 <strong class="calibre14">any</strong> program or script (such as the <a href="#Send.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Send</a> or <a href="#MouseMove.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">MouseMove</a> 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. </td>
</tr>
<tr class="calibre3">
<td class="calibre4">A_TimeIdlePhysical</td>
<td class="calibre4 tbd">
<td class="calibre4 rm">A_TimeIdlePhysical</td>
<td class="calibre4 rm">
<p class="calibre8"><a id="Variables.htm__TimeIdlePhysical" href="#Variables.htm__TimeIdlePhysical" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a> Same as above but <strong class="calibre14">ignores</strong> artificial input whenever the corresponding hook (<a href="#h_InstallKeybdHook.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">keyboard</a> or <a href="#h_InstallMouseHook.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">mouse</a>) 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.</p>
</td>
</tr>
Expand Down
3 changes: 3 additions & 0 deletions src/run/display.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/run/runner.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit e5660cb

Please sign in to comment.