ZeroTrace HID
Variables
Declare, reference, and mutate values, and read live device states
Variables store and reuse values. A variable can hold a static value, an operator expression, or a device state.
Declaring and referencing
- Declare with
_$VAR. - Assign with
=, and the value must be quoted (double quotes). - Reference the value inside any argument with
${name}$.
# Static value
_$VAR isAdmin = "true"
writeLn "${isAdmin}$"
# Operator inside a variable
_$VAR delayTime = "_$random(500, 1500)"
delay "${delayTime}$"
# State inside a variable
_$VAR capsStatus = "_@capslockState"
writeLn "${capsStatus}$"
Common mistakes: leaving the value unquoted (_$VAR name = admin), referencing without the ${…}$ wrapper (writeLn "$isAdmin"), or using a variable that was never declared.
Runtime assignment and math
_$VAR declares a variable when the line is read. To change a value while the script runs — for example to drive a repeat/while counter — use the commands below. They operate on the same global variables you reference with ${name}$.
| Command | Syntax | Effect |
|---|---|---|
set | set <var> <value> | Assign value to var |
add | add <var> <n> | var = var + n |
sub | sub <var> <n> | var = var - n |
mul | mul <var> <n> | var = var * n |
mod | mod <var> <n> | var = var % n (unchanged if n is 0) |
The math commands treat the variable as a signed integer in base 10; a non-numeric current value is read as 0.
set counter "0"
whileStart "${counter}$" < "3"
writeLn "Line ${counter}$"
add counter 1
whileEnd
set/add/sub/mul/mod take the variable name unquoted (e.g. add counter 1), while IF/while conditions take the value reference quoted (e.g. "${counter}$").
How a reference is resolved
When you use "${name}$", the interpreter looks up the global variable and then, if its stored value contains a marker:
- Evaluates operators if the value contains
_$. - Resolves a state if the value contains
_@— and lowercases the result.
Device states
State-backed values can be used standalone or embedded in text.
| State | Description | Raw output |
|---|---|---|
_@capslockState | CapsLock state | on / off |
_@numlockState | NumLock state | on / off |
_@scrolllockState | ScrollLock state | on / off |
_@usbState | USB connection state | on / off |
_@detectedOS | Detected operating system | Windows / Linux / macOS / iOS / Android / Unknown OS / OS Detection Disabled / Waiting... |
When a state is resolved through ${name}$ (including inside IF/while conditions), the value is lowercased — _@detectedOS becomes windows, macos, linux, and the lock/USB states become on / off. Always compare against lowercase.
_$VAR usbStatus = "_@usbState"
writeLn "USB is: ${usbStatus}$"
Practical examples
Dynamic delay
_$VAR delayTime = "_$random(500, 1500)"
delay "${delayTime}$"
OS-aware branch
_$VAR os = "_@detectedOS"
IF "${os}$" is "windows"
terminal 'windows' powershell
IF_END
Combining an operator and text
_$VAR username = "_$random(1, 100)"
writeLn "Generated user: ${username}$"