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

    Timer On Keypress

      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"

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

          on endCheck
          checking = false

          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

          on exitFrame me


          Dave -
          Head Developer
          Adobe Community Expert