Threads


Multithreading is supported by standard Java classes

var Runnable = Java.type('java.lang.Runnable');
var Thread = Java.type('java.lang.Thread');

var moveX = Java.extend(Runnable, {
    run: function() {
        var x0 = mouse.getX();
        for(var i=0;i<100;i++){
            mouse.move(1,0);
        }
        system.println('dx='+(mouse.getX()-x0));
    }
});

var moveY = new Thread(function() {
    var y0 = mouse.getY();
    for(var i=0;i<100;i++){
        mouse.move(0,1);
    }
    system.println('dy='+(mouse.getY()-y0));
});

new Thread(new moveX()).start();
moveY.start();

Note that all method calls to the control objects (key, mouse, system, combined, clipboard) are synchronized. This concerns both the threads running from the script and threads running HTTP and Socket servers. If one thread takes a method, even if it uses a separate control object, then all control methods will not be available for other threads. This situation can occur if a large auto-delay is established for the key or mouse object, as well as freezing the methods of the clipboard object.

        

This restriction does not apply to the system.sleep () method, since it is solely related to the current thread. The delay set through this method can be any value.

        

List of non-synchronized methods