Trapping the escape key inside a loop

Sarah Reichelt sarah.reichelt at gmail.com
Tue Apr 6 20:21:39 EDT 2010


On Wed, Apr 7, 2010 at 10:14 AM, David Coker <davidocoker at gmail.com> wrote:
> Howdy folks,
> Scratching my head in wonderment again, trying to figure out why I
> can't trap the escape key.
> Here is a sample script that I've been playing with outside of my real
> app that is pretty close to the real thing:
>
> global gStop
>
> on mouseUp
> put 0 into gStop
> do ThisHandler
> do ThatHandler
>  repeat with i = 1 to 10000
>    if gStop = 1 then exit repeat
>      do some useful work here
>  exit repeat
> do CleanUpRoutine
> end mouseUp


You have to give your repeat loop a break so the system has time to
detect the escape key.
Try this:

global gStop

on mouseUp
   put false into gStop
   repeat with x = 1 to 1000
      put x into fld 1
      if gStop = true then exit repeat
      wait 0 milliseconds with messages   -- allows detection of other events
   end repeat
end mouseUp

And in the card or stack script:

global gStop

on escapeKey
   put true into gStop
end escapeKey


Cheers,
Sarah



More information about the use-livecode mailing list