Skip to content

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

  1. Declare with _$VAR.
  2. Assign with =, and the value must be quoted (double quotes).
  3. 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}$.

CommandSyntaxEffect
setset <var> <value>Assign value to var
addadd <var> <n>var = var + n
subsub <var> <n>var = var - n
mulmul <var> <n>var = var * n
modmod <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:

  1. Evaluates operators if the value contains _$.
  2. Resolves a state if the value contains _@ — and lowercases the result.

Device states

State-backed values can be used standalone or embedded in text.

StateDescriptionRaw output
_@capslockStateCapsLock stateon / off
_@numlockStateNumLock stateon / off
_@scrolllockStateScrollLock stateon / off
_@usbStateUSB connection stateon / off
_@detectedOSDetected operating systemWindows / 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}$"

Command Palette

Search for a command to run...