Skip to content

Commit

Permalink
add more built-in variables: A_ScreenWidth, A_ScreenHeight, A_UserNam…
Browse files Browse the repository at this point in the history
…e, A_IsAdmin, A_ComputerName
  • Loading branch information
phil294 committed Dec 10, 2022
1 parent d506e82 commit 8ff67d0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
12 changes: 6 additions & 6 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1829,11 +1829,11 @@ <h4 class="calibre25"><a id="Variables.htm__os" href="#Variables.htm__os" class=
</tr>
<tr class="calibre3">
<td class="calibre4">A_ComputerName</td>
<td class="calibre4"><a id="Variables.htm__ComputerName" href="#Variables.htm__ComputerName" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a><span class="tbd"> The network name of the computer. [requires 1.0.24+]</span></td>
<td class="calibre4"><a id="Variables.htm__ComputerName" href="#Variables.htm__ComputerName" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a> The network name of the computer.</td>
</tr>
<tr class="calibre3">
<td class="calibre4">A_UserName</td>
<td class="calibre4"><a id="Variables.htm__UserName" href="#Variables.htm__UserName" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a> <span class="tbd">The logon name of the current user. [requires 1.0.24+]</span></td>
<td class="calibre4"><a id="Variables.htm__UserName" href="#Variables.htm__UserName" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a> The logon name of the current user.</td>
</tr>
<tr class="calibre3">
<td class="calibre4">A_WinDir</td>
Expand Down Expand Up @@ -1885,16 +1885,16 @@ <h4 class="calibre25"><a id="Variables.htm__os" href="#Variables.htm__os" class=
</tr>
<tr class="calibre3">
<td class="calibre4">A_IsAdmin</td>
<td class="calibre4"><a id="Variables.htm__IsAdmin" href="#Variables.htm__IsAdmin" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a><span class="tbd"> If the current user has admin rights, this variable contains 1. Otherwise, it contains 0. Under Windows 95/98/Me, this variable always contains 1. [requires v1.0.10+]</span></td>
<td class="calibre4"><a id="Variables.htm__IsAdmin" href="#Variables.htm__IsAdmin" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">#</a> If the current user has admin rights, this variable contains 1. Otherwise, it contains 0.</td>
</tr>
<tr class="calibre3">
<td class="calibre4">
<p class="calibre8">A_ScreenWidth<br class="calibre12" /> A_ScreenHeight</p>
</td>
<td class="calibre4 tbd">
<p class="calibre8"><a id="Screen" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2"></a>The width and height of the primary monitor, in pixels (e.g. 1024 and 768). [requires v1.0.22+]</p>
<td class="calibre4">
<p class="calibre8"><a id="Screen" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2"></a>The width and height of the primary monitor, in pixels (e.g. 1024 and 768).</p>
<p class="calibre8">To discover the dimensions of other monitors in a multi-monitor system, use <a href="#SysGet.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SysGet</a>.</p>
<p class="calibre8">To instead discover the width and height of the entire desktop (even if it spans multiple monitors), use the following example (but on Windows 95/NT, both of the below variables will be set to 0):<br class="calibre12" />
<p class="calibre8">To instead discover the width and height of the entire desktop (even if it spans multiple monitors), use the following example<br class="calibre12" />
<a href="#SysGet.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SysGet</a>, VirtualWidth, 78<br class="calibre12" />
<a href="#SysGet.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">SysGet</a>, VirtualHeight, 79
</p>
Expand Down
1 change: 1 addition & 0 deletions src/ahk_x11.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require "./build/builder"
require "./run/runner"
require "./compiler"
require "./logo"
require "./hacks"

fun main(argc : Int32, argv : UInt8**) : Int32
# It's also possible to run everything *without* `preview_mt` and spawn threads manually instead.
Expand Down
13 changes: 13 additions & 0 deletions src/hacks.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Place for syntax problems, workaround, missing stdlib methods etc.
# Every entry needs to be explained and should be avoided whenever possible.

lib LibC
# Query user name: https://stackoverflow.com/q/67591891
fun getuid : UidT
end

class Hacks
def self.username
System::User.find_by(id: LibC.getuid.to_s).username
end
end
15 changes: 10 additions & 5 deletions src/run/runner.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require "./thread"
require "./timer"
require "./display/hotkey"
require "../cmd/base"
require "system/user"

module Run
enum SingleInstance
Expand Down Expand Up @@ -29,7 +30,7 @@ module Run
class Runner
# These are editable by the user
@user_vars = {} of String => String
# These are only changed by the program. See also `get_global_built_in_computed_var`
# These are only set by the program. See also `get_global_built_in_computed_var`
@built_in_static_vars = {
"a_space" => " ",
"a_tab" => "\t",
Expand Down Expand Up @@ -226,6 +227,7 @@ module Run
def set_global_built_in_static_var(var, value)
@built_in_static_vars[var.downcase] = value
end
# These are only set by the program. See also `built_in_static_vars`.
# `var` is case insensitive
private def get_global_built_in_computed_var(var)
case var.downcase
Expand All @@ -243,10 +245,13 @@ module Run
when "a_now" then Time.local.to_YYYYMMDDHH24MISS
when "a_nowutc" then Time.utc.to_YYYYMMDDHH24MISS
when "a_tickcount" then Time.monotonic.total_milliseconds.round.to_i.to_s
when "clipboard"
display.gui.clipboard &.wait_for_text
else
nil
when "clipboard" then display.gui.clipboard &.wait_for_text
when "a_screenwidth" then display.adapter.display.default_screen.width.to_s
when "a_screenheight" then display.adapter.display.default_screen.height.to_s
when "a_username" then Hacks.username
when "a_isadmin" then Hacks.username == "root" ? "1" : "0"
when "a_computername" then `uname -n`
else nil
end
end

Expand Down

0 comments on commit 8ff67d0

Please sign in to comment.