Interrupt Timer - by Code Maker 2017
This program can periodic execute code without any calls from the
I am sure there is many applications opportunities for an interrupt
timer like this.
You sould try to keep the timer delay above 10 milliseconds or
else it will overload your system, to quote MS API SDK help files
"Periodic timer events with an event delay of 10 milliseconds or less
consume a significant portion of CPU resources."
The interrupt timer will bee killed if the window to which it has been
associated is closed.
`Interrupt Timer - by Code Maker 2017
`this code needs the Matrix1 plugin to compile
`You sould try to keep the timer delay above 10 milliseconds or
`else it will overload your system, to quote MS API SDK help files
`"Periodic timer events with an event delay of 10 milliseconds or less
`consume a significant portion of CPU resources."
`The interrupt timer will bee killed if the window to which it has been
`associated is closed.
sync rate 60
user32DLL = 1
timerdelay = 1000 `timer delay in milliseconds
x = screen width()
y = screen height()+50
text$ = "mainloop is dooing this..."
set window title "Interrupt Timer by Code Maker 2017"
`load user 32 bit dll
load dll "user32.dll", user32DLL
`get window handle, identifies the window to be associated with the timer
WindowHWND = call dll(user32DLL, "GetActiveWindow")
`get pointer to function
InterruptTimerPTR = get ptr to function("InterruptTimer")
`make timer, it starts immediately
TimerID = call dll(user32DLL, "SetTimer", WindowHWND, 1, timerdelay, InterruptTimerPTR)
if x<-text width(text$) then x=screen width()
if y<-text height(text$) then y=screen height()+15
if inkey$()<>"" then exit
text x, 200, text$
text screen width()/2-text width(ittext$)/2, y, ittext$
`clean up before exit
s = call dll(user32DLL, "KillTimer", WindowHWND, TimerID)
delete dll user32DLL
`function, this is what the interrupt timer will do
ittext$ = "interrupt timer is doing this, without any calls from the mainloop " + str$(counter)