Function on Keypress hold

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
aircooled76
Posts: 38
Joined: Mon May 20, 2013 3:14 pm

Function on Keypress hold

Post by aircooled76 » Sun May 27, 2018 9:50 pm

Hi Guys,

I am looking for a way to have a process (video cut) to happen when the "a" key is pressed but a different process (video fade) to happen if the "a" key is held down for a period of time (say 50ms.)

I have been looking at the keysdown function and making a repeat loop but I can't get anything to trigger with the keysdown function when the key is pressed.

Any help appreciated.

Code: Select all

on keyDown theKey
   if theKey is "a"
   
   then
      answer "a"
      
      if "a" is in the keysdown
      then
         answer "a is down"
      else 
         
      end if
   end if
end keydown

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Function on Keypress hold

Post by jmburnod » Sun May 27, 2018 10:31 pm

Hi,
It seems you need do something with keyup
period of time (say 50ms.)
50 seems short
Something like that:

Code: Select all

local sStartTime
on keyDown theKey
   put the milliseconds into sStartTime
end keydown

on keyup theKey
   if pKey = "a" then
      if the milliseconds < (sStartTime + 50) then
         doVideoCut
      else
         doVideoFade
      end if
   end if
end keyup
Best regards
Jean-Marc
https://alternatic.ch

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”