Speed and delay multiplier
For more flexible customization, there are delay multipliers multiplier and minimal delays minDelay. A delay multiplier is a real number by which every delay is multiplied by. They are contained in the mouse, key and system object and work likewise. Standard delay and speed multiplier = 1. Let's have a look at an example
mouse.setMultiplier(0.5);
key.setMultiplier(0.5);
system.setMultiplier(0.5);
mouse.press('LEFT');
mouse.release('LEFT');
system.sleep(1000);
key.press('A');
key.release('A');
By calling etMultiplier, we set the multiplier to 0.5. This means that in the internal
implementation, the standard delay, for example pressDelay, will be multiplied by this number,
which means it is halved. In this way, by setting a delay of less than 1, you can speed up the playback of
events, and by setting the multiplier more than 1 slow down.
For ease of use, there is a reverse parameter speed, which displays the speed of event
playback. By default it is also 1, which means the script will play all the events without changing the delay.
If you set the speed as 2, it means that the playback speed will increase by two.
The speed parameter is the reciprocal of multiplier, changing one of these
changes the second. For example, if speed = 2, then multiplier = 0.5.
In the example below, the initial speed is set to 1 and with each iteration the cursor movement speed increases
by 10%
var speed = 1;
while(speed < 5){
system.println('speed = '+speed);
mouse.setSpeed(speed);
system.setSpeed(speed);
moveMouse();
speed*=1.1;
}
function moveMouse(){
combined.run('base64','AgDwgDeDgAJAgDzgDgDgAYAg'+
'D3gDhDgAoAgD9gDkDgAoAgEBgDoDgAgAgEEgDqDgAYAgEE'+
'gDsDgAgAgEFgDuDgAgAgEFgDyDgAgAgEFgD1DgAgAgEFgD'+
'3DgAoAgEDgD+DgAgAgECgEBDgAgAgEBgECDgAgAgD+gEFD'+
'gAgAgD7gEIDgAgAgD1gEMDgAgAgDugEQDgAgAgDpgETDgA'+
'wAgDhgETDgAYAgDdgETDgAgAgDYgESDgAgAgDRgEPDgAgA'+
'gDOgELDgAgAgDKgEFDgAgAgDGgD/DgAgAgDFgD5DgAoAgD'+
'EgDzDgAgAgDEgDtDgAgAgDFgDpDgAgAgDIgDlDgAgAgDMg'+
'DhDgAgAgDRgDeDgAgAgDXgDcDgAgAgDfgDaDgAoAgDlgDZ'+
'DgAgAgDogDZ');
}
Increasing the execution speed of the script means that the delays between events decrease. At very small delays,
the script may start to work incorrectly or completely stop its work. To solve this problem, each object has a
minimum delay parameter minDelay, which limits the minimum possible value of delay. By default
it is set to 5 ms. It can also be set by the respective method and be set to 0, which is not recommended. If you
decide to set the minimum delay value to 0, then be very careful and watch for delays yourself, otherwise the
script may freeze.
It is not recommended to set delay values lower then 10 ms. To speed up the script, it is best to use only the
system.speed parameter, which only changes the delays passed to the
system.sleep(delay) method. Delays in this method may well be equal to 0, which won't stops or
corrupt script execution in any way. When system.speed is set to 0, and other delays and
multipliers in standard values, the maximum number of events is 100 events per second, which is still more than
enough to work.
For a better understanding of the interactions of delays, multipliers and minimum delays, let's have a look at
the example of the keystroke event
// Any event happens instantly
// without any delays, immediately after the method calling
press ('A');
// After the event, a delay is added
//
// Compute the delay multiplying it by multiplier
var delay = pressDelay * multiplier;
if (delay & gt; = minDelay) {
// if the delay value for the event is greater than the minimum delay,
// then wait for the specified number of ms.
sleep (delay);
} else {
// if the resulting delay is less than the minimum delay,
// then wait for the minimum allowed number of ms.
sleep (minDelay);
}