Code: Select all
Initialize
Timer.Items(Timer1).Interval = 1 Timer.Items(Timer1).OnTimer = @OnTimer1 // 1 Ms
Timer.Items(Timer1).Enabled = True
Timer.Start
Moderators: David Barker, Jerry Messina
Code: Select all
Initialize
Timer.Items(Timer1).Interval = 1 Timer.Items(Timer1).OnTimer = @OnTimer1 // 1 Ms
Timer.Items(Timer1).Enabled = True
Timer.Start
Code: Select all
Event OnTimer1()
Inc(Zms)
End Event
Const Timer1 = 0
Code: Select all
Public Sub Bir(pBas As Integer)
SendKey(30)
Repeat Until Zms = pBas
SendKey(0)
Zms = 0 Rd
End Sub
Code: Select all
Event OnTimer1()
Inc(Zms)
End Event
Code: Select all
Sub OnTimer1()
Inc(Zms)
End sub
Code: Select all
Public Sub Bir(pBas As word)
dim tZms as word // temp copy of Zms
SendKey(30)
// block isr so event doesn't run while we reset Zms
Timer.Fblock = true
Zms = 0
tZms = 0
Timer.Fblock = false
while (tZms < pBas)
Timer.Fblock = true // block isr so Zms doesn't incr while being read since it's a word
tZms = Zms
Timer.Fblock = false
end while
SendKey(0)
Rd
End Sub
That's probably not a good idea. It might work, but the OnTimer1 routine is called by the timer ISR, and SendKey interacts with the USB interrupt.I will also send key presses in ontimer subroutine
Code: Select all
Public Sub Iki(pBas As Integer)
SendKey(31)
Repeat Until Zms = pBas
SendKey(0)
Zms = 0
Rd
End Sub
Code: Select all
Public Event OnTimer1()
Inc(Zms)
End Event
I set Zms to zero before this, so it counts to my preferred milliseconds.Jerry Messina wrote: I assume the purpose of this routine is to mimic pressing a key for 'pBas' msecs, and then releasing it?
If so, you'll almost always get stuck in the 'Repeat Until Zms = pBas' loop for about 65 seconds (until Zms wraps around and meets pBas).
I will take this into consideration, thanks.In addition, you shouldn't try to use a 16-bit value in the ISR event and the main loop without protecting
it from being interrupted.
That works on 2.1.0.0 version but not on last one. This would help me this code's future variations.Also, you can't use Send or SendKey in both the main routine body and the Timer event.
Either send keys in the timer event or send them in main, but not both. The Timer event is called
from the timer ISR, so it's possible that the event will interrupt a SendKey that's already in
process, and this just won't work.
Probably i will have to do this, but last.You'll have a lot more luck just letting the timer event track the time and doing the rest in your main loop.