Delays


There are delays between any events and method calls. To implement delays, the system.sleep(delay) method exists. He tells the system to wait at this point in the script for the specified number of milliseconds and then continue execution. Delays are used to simulate real user behavior. A real person can not instantly print more than 100 characters and not every program is able to correctly process input of this kind, some events will simply be missed. Therefore, the script must be forced to be slowed down. Below is an example of a script for typing the word Hello which is written from the actions of a real person.

key.press('SHIFT');
system.sleep(228);
key.press('H');
system.sleep(65);
key.release('H');
system.sleep(25);
key.release('SHIFT');
system.sleep(142);
key.press('E');
system.sleep(60);
key.release('E');
system.sleep(95);
key.press('L');
system.sleep(65);
key.release('L');
system.sleep(78);
key.press('L');
system.sleep(66);
key.release('L');
system.sleep(102);
key.press('O');
system.sleep(70);
key.release('O');

Note the delays between events. In sum, this is exactly the time that a real person needs to print a given word. Without delays, user input is not possible. You can try to execute a script with zero delays, most likely it will freeze.