Send keys periodically

Post your working scripts, libraries and tools for AHK v1.1 and older
william_ahk
Posts: 499
Joined: 03 Dec 2018, 20:02

Send keys periodically

05 Dec 2020, 22:23

Code: Select all

Menu, Tray, Icon, AutoHotkey.exe, 4

keys := [["1", 1000], ["2", 2000]]
timers := []

F1::
{
toggle := !toggle
if (toggle) {
    for index, value in keys {
        send % value[1]
        timers.Push(set_interval("key_emitter", value[1], value[2]))
    }
    Menu, Tray, Icon, AutoHotkey.exe, 1
} else {
    for index, value in timers {
        rm_interval(value)
    }
    timers := []
    Menu, Tray, Icon, AutoHotkey.exe, 4
}
return
}

set_interval(fn, param, interval) {
    fn_obj := Func(fn).Bind(param)
    SetTimer % fn_obj, % interval
    return fn_obj
}

rm_interval(fn_obj) {
    SetTimer % fn_obj, Delete
}

key_emitter(key) {
    send % key
}
Basically this will send keys periodically with an on/off function. I searched around the forum but couldn't find anything like this, so I wrote one. If there's a better solution please comment below :)

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 69 guests