simulate keystroke
J. Landman Gay
jacque at hyperactivesw.com
Sun Oct 26 22:11:27 EDT 2008
J. Landman Gay wrote:
> Larry Watts wrote:
>> hi Mark,
>> What I'm really wondering how to do is this:
>> I have a button script running with a lot of repeat statements in it.
>> Depending upon the input, the script will run for 5 minutes to an
>> hour. I want the user to be able to interrupt the script by clicking
>> on another button on the card. But as I understand it, Rev cannot do
>> that because the first button has the focus until the entire script is
>> finished running. Is there a way to work around this limitation of Rev?
>
> Yes, and the workaround is the preferred method. Running a repeat loop
> that long doesn't just lock up Rev, it locks up the whole CPU. Here's
> the preferred solution: <http://www.hyperactivesw.com/polling.html>.
It just occured to me that your repeat loop probably doesn't track the
mouse, so the link I gave isn't a good reference. What I'd use instead
is a "send in <time>" statement that calls a handler repeatedly until
the work is done. This will avoid taking all the CPU cycles too, because
a time slice is given to other processes in between the "send"s.
A simple example:
on mouseUp -- the button that starts the processing
set the cProcessFlag of me to true
send "doProcess" to me in 1 millisecond -- can be adjusted
end mouseUp
on doProcess
if <some quit condition; maybe the data is empty, etc> or \
the cProcessFlag of me = false then
set the cProcessFlag of me to false -- in case the quit condition
got us here
else
doSomeProcessing
send "doProcess" to me in 1 millisecond
end if
end doProcess
And in the button that interrupts the processing:
on mouseUp
set the cProcessFlag of btn "start button" to false
end mouseUp
--
Jacqueline Landman Gay | jacque at hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
More information about the use-livecode
mailing list