[class][v2] quickTimer - fast callback timer.

Post gaming related scripts
Posts: 3163
Joined: 17 Jul 2016, 01:02

[class][v2] quickTimer - fast callback timer.

07 Jun 2018, 05:28

Note: this script is for :arrow: AHK v2.
I post this in the gaming section because I guess gamers might be more interested in it, and the main example is a classic gaming example, a spam script, however, usage is not limited to gaming.

See :arrow: github for latest version.

When to use?
When the timer callback needs to fire frequently and completes very fast, if you use any sleeps, keydelays or other wait functions in the callback, you do not need this timer.

Test result
This is the result from the speed test example,
regularTimer.png (10.53 KiB) Viewed 245 times

quickTimer.png (10.36 KiB) Viewed 245 times

Basic usage
Usage is very simple, create a timer, call start() and stop(),

Code: [Select all] [Download] GeSHi © Codebox Plus

#include timer.ahk
sendMode "event"
setkeydelay -1, -1
callback := func("send").bind("z")
qt := new quickTimer(callback)
f1 up::qt.stop()

Available methods:
  • start, start the timer.
  • stop, stop the timer.
  • delete, delete the timer, do not use again when deleted.
  • startAll, starts all timers.
  • stopAll, stops all timers.
  • deleteAll, deletes all timers.

Only send keys with sendmode "sendevent" and setkeydelay -1, -1. Always include a hotkey to close the script, eg esc::exitapp.

How does it work?
While any timer is active, the class keeps a thread running which basically only does loop { sleep(-1) }, this prevents the running AutoHotkey.exe from doing its internal sleep and instead it will check its message queue, and there is no sleeping between timer messages.

This is experimental. CPU usage will be much higher. Your regular timers will also be fast while a quickTimer is active.

Self-contained example
This is a classic spam script. Hotkeys a and b sends a and b using quickTimer. Hotkey c and d sends c and d using regular timers. esc exits the script.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 4 guests