1 Reply Latest reply on Jul 16, 2007 10:44 AM by Newsgroup_User

    Timer On Keypress

    neal2000uk Level 1
      I am trying to come up with some lingo that will recognise how long a key has been held down for. I am trying to make some code so that, for example, when "a" is help down for 2 seconds, I will jump to a different frame, but if "a" is realsed before 2 seconds it does nothing. I noticed there is a startTimer but not a stopTimer command so it is not as simple as resetting the timer on Keyup. I am quite new to Lingo so if you do have suggestions please comment any code.
        • 1. Re: Timer On Keypress
          Level 7
          Various ways to do this... Here's one:

          Put this in a movie script:

          global checking, keyTime

          on startMovie
          checking = false
          the keyDownScript = "startCheck"
          the keyUpScript = "endCheck"
          end

          on startCheck
          if _Key.key = "a" and not checking then
          keyTime = _system.milliseconds
          checking = true
          end if
          end

          on endCheck
          checking = false
          end

          Then put this into frame 1 script:

          global checking, keyTime

          on enterFrame me
          if checking then
          if _system.milliseconds - keyTime > 2000 then
          --do stuff
          trace("key held for two seconds")
          checking = false
          end if
          end if
          end

          on exitFrame me
          _movie.go(_movie.frame)
          end


          HTH

          --
          Dave -
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/