MULTIBOXING COMMANDS

DoHotkeyAsync

Triggers a hotkey. This is the asynchronous version of this command.

Syntax

DoHotkeyAsync ( delay trigger )

Parameters

Delay is the number of milliseconds that passes before DoHotkeyAsync triggers the hotkey.

Trigger is the key or key combination of the hotkey.

Remarks

DoHotkeyAsync works exactly like triggering a hotkey with your fingers.

Unlike most Mojo commands this one executes in Mojo itself, not in a DAOC window, so if you put it in a package that goes to several DAOC windows on one computer, it will execute only once. The synchronous version is different in this respect.

DoHotkeyAsync can trigger the same hotkey or a different one. For example, both of these work:

Hotkey ( F1 )
{
   DoHotkeyAsync ( 3500 F1 )
}

Hotkey ( F1 )
{
   DoHotkeyAsync ( 3500 F2 )
}

Note: If you make a hotkey like the first one above, make sure you also make a hotkey with Cancel in it. You’ll need it!

This command is called “async” for asynchronous. What does that mean? Commands usually execute in the order you write them. But asynchronous commands don't work like that. For example, in the following hotkey, you might think Key(3) happens first, then Hotkey F2 happens a second later.

Hotkey ( F1 )
{
   Key ( 3 )
   Wait ( 1000 )
   DoHotkeyAsync ( 0 F2 )
} 

But no, Hotkey F2 happens instantly after you press F1. Why? Because you wrote 0. That means, "execute DoHotkeyAsync 0 milliseconds after I press F1."

To make F2 execute one second after Key(3), we can write the hotkey like this:

Hotkey ( F1 )
{
   Key ( 3 )
   DoHotkeyAsync ( 1000 F2 )
}
The order of commands doesn't matter with DoHotkeyAsync, so the same hotkey could be written like this:
Hotkey ( F1 )
{
   DoHotkeyAsync ( 1000 F2 )
   Key ( 3 )
}

Why does Mojo use this method of specifying the time at which DoHotkeyAsync executes? Because Mojo's hotkeys are multithreaded and this can sometimes confuse people. The easiest way to elminate confusion is to allow people to write the number of milliseconds in this way. No matter how complicated a hotkey becomes, no matter how many threads it expands into, the number in DoHotkeyAsync always measures the delay from the start of the hotkey. That principle is rock solid and super simple.

Related

Cancel

Wait

This page was first published on November 2, 2017 and last modified on November 3, 2017