Skip to main content

Vectors

Vectors are one of the two types of variables present in Simkey. They are essentially analogous to number arrays, and they have several components which correspond to numbers.

You can use a vector as a number for the sake of passing in arguments to functions or setting inline delays, with it automatically referring to the first component of the vector.

First we will discuss how to declare them to begin with.

How to declare a vector

Vectors are declared in the VECTORS section, where assignments are interpreted as such and not as literal key expressions. Here's an example:

<VECTORS>
$my_delays = 50,50 # Vector $my_delays with first and second component being 50 #
$my_num = 0 # Only declared one component #

<MACRO>
# Do whatever here... #

There is no limit around how many components you can have, but the minimum it will have is two, even if you declare only one. The second will be 0 by default.

note

There are many ways to declare vectors without putting it in VECTORS section by using a builtin, importable function, or simkey function parameters. These will be discussed later.

How to use vectors

There's generally four ways you can refer to the value(s) of a vector:

  1. As a whole vector
  2. As a component at a specific index ($vector_name:[index])
  3. As a component at an index from a math expression ($vector_name:([expression]))
  4. As a number ― automatically refers to the first component

Simkey uses zero as the base for indexing, so $vector_name:0 would refer to the first component. When using an index, even if it is with an expression, there must not be a space in the entire vector reference.

The actual usage of these values arises when calling functions or setting delays inline in a key expression. Here's an example:

<VECTORS>
$my_vector = 0,1,2,3,4,5

<MACRO>
@delay [$my_vector] # Takes first (0) as `hold` and second (1) as `wait` #

@repeat [$my_vector] { # Will talk about @repeat later, but this repeats zero times #
# ... #
}

@repeat [$my_vector:1] { # This repeats one time
# ... #
}

@repeat [$my_vector:($my_vector:1+1)] { # This repeats two times #
# ... #
}

<$my_vector>abc<$my_vector:5> # Hold is 0ms, wait is 5ms #

Getting vectors input from the app

You can allow certain vectors to get input from the Simkey App by simply writing | input after your default values. The input will be the exact same length as your default values, and if no input is given, then the vectors will just have the values you assigned. Example:

<VECTORS>
$wait = 100 | input

<MACRO>
# Waits by that amount, then clicks #
<$wait>
[MB_LEFT]

How to update vectors

You can use builtin functions to update vectors, and there is no assignment outside of the VECTORS section for them due to the nature of the language. You can either treat it as a number and only consider the first component, or set it at any index you would like.

Here's an example, using @set and @setIndex builtin functions:

<VECTORS>
$my_vector = 0,1,2,3,4,5

<MACRO>
@set [$my_vector, 25] # Sets the first component to 25 from 0 #
@setIndex [$my_vector, 5, 6] # Sets the last component to 6 from 5 #

# $my_vector is now 25,1,2,3,4,6 #