Detecting a prolonged button press

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Detecting a prolonged button press

Post by grovecat »

I need to ignore a button press unless it is held for more than a couple of seconds and I tried the following code, which does not work.

Code: Select all

local tDown

on mouseDown
   send checkMouse to me in 3 secs
end mouseDown

on checkMouse
   put false into tDown
   wait 1 sec
   if tDown is true then answer "It was held down"
end checkMouse

on mouseStillDown
   put true into tDown
end mouseStillDown
Help appreciated.

TIA
Don
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Detecting a prolonged button press

Post by bn »

Hi Don,

try this

Code: Select all

local sStartTime
on mouseDown
  put the milliseconds into sStartTime
end mouseDown

on mouseUp
   put the milliseconds - sStartTime into tTimeDiff
   if tTimeDiff > 3000 and tTimeDiff < 6000 then -- between 3 and 6 seconds
      -- process your mouseUp
      answer "right time delay"
   end if
end mouseUp
Kind regards

Bernd
grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Re: Detecting a prolonged button press

Post by grovecat »

Thanks Bernd

An elegant solution that works fine. However, I would prefer the processing to start after the 3 secs or whatever, while the mouse is still being held down. Can you see a way to do that?

Cheers
Don
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Detecting a prolonged button press

Post by bn »

Hi Don,

try this

Code: Select all

local sStartTime
on mouseDown
   put the milliseconds into sStartTime
   send checkTime to me in 5 milliseconds
end mouseDown

on checkTime
   put the milliseconds - sStartTime into tTimeDiff
   if tTimeDiff < 3000 and the mouse is down then
      send checkTime to me in 50 milliseconds
      exit checkTime
   end if
   if tTimeDiff > 3000 and the mouse is down then
      -- process your code
      answer " right timeDelay"
   end if
end checkTime
Kind regards

Bernd
grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am

Re: Detecting a prolonged button press

Post by grovecat »

That is exactly what I needed.

Thanks again Bernd.

Cheers
Don
Post Reply