Download
I don't really feel that we have a decent solution for timers down to 1ms, which (Especially when trying to write mouse "Delta" movement scripts, is a bit of a pain.
QPX just doesn't quite scratch that itch for me...
So now that I am getting into C# coding, I thought I would try to implement something better.
I found an cool little library on Codeplex by Ken Loveday, so I wrapped that into a DLL, and added some tweaks to have it behave basically like SetTimer.
It uses Lexikos' CLR library to load the DLL and create a timer object from the DLL.
You pass it a Function Object and a time in the same format as SetTimer (in ms, negative to only fire once) and it fires the callback at the frequency you requested.
It's not 100% accurate, but it is pretty good (Especially once it settles down) and it goes down to 1ms, so you can, for example, get nice regular 1ms calls to mouse_event so your mouse moves smoothly.
Here is a demo script to map the arrow keys to mouse delta movement, with it making the DLL call once every millisecond.
Code: Select all
#include CLR.ahk
/*
Demo Script for MicroTimer
Converts Arrow Keys to mouse cursor, with 1ms move time for the mouse
*/
#SingleInstance force
if (!FileExist("MicroTimer\MicroTimer.dll")){
MsgBox DLL Not found
ExitApp
}
asm := CLR_LoadLibrary("MicroTimer\MicroTimer.dll")
; Use CLR to instantiate a class from within the DLL
mt := asm.CreateInstance("MicroTimer")
XState := 0
YState := 0
XTimer := mt.Create(Func("MoveX"), 1)
YTimer := mt.Create(Func("MoveY"), 1)
return
MoveX(){
global XState
DllCall("user32.dll\mouse_event", "UInt", 0x0001, "UInt", XState, "UInt", 0, "UInt", 0, "UPtr", 0)
}
MoveY(){
global YState
DllCall("user32.dll\mouse_event", "UInt", 0x0001, "UInt", 0, "UInt", YState, "UInt", 0, "UPtr", 0)
}
XEvent(evt){
global XState, XTimer
XState := evt
XTimer.SetState(abs(XState))
}
YEvent(evt){
global YState, YTimer
YState := evt
YTimer.SetState(abs(YState))
}
~Left::
XEvent(-1)
return
~Right::
XEvent(1)
return
~Left up::
~Right up::
XEvent(0)
return
~Up::
YEvent(-1)
return
~Down::
YEvent(1)
return
up up::
down up::
YEvent(0)
return
^Esc::
ExitApp