checkingMousedownDuration

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

checkingMousedownDuration

Post by jmburnod » Tue Jul 03, 2012 6:48 pm

Hi All,

I try to have two messages for a mousedown.
One if the duration of the mousedown < 2 seconds and one if > 2 seconds

I explored two ways :

One with a repeat loop
One with a "send message in" (pendingmessage)

What is the best for you ?

Best regards

Jean-Marc
Attachments
CheckingMousedownDuration.livecode.zip
(1.54 KiB) Downloaded 192 times
https://alternatic.ch

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: checkingMousedownDuration

Post by Dixie » Tue Jul 03, 2012 6:58 pm

Jean Marc...

maybe..

Code: Select all

local tStart

on mouseDown
   put the millisecs into tStart
end mouseDown

on mouseUp
   put the millisecs - tStart into theTimeTaken
   if theTimeTaken > 2000 then
      answer "Took more than 2 seconds"
   else
      answer "Took less than 2 seconds"
   end if
end mouseUp
be well

Dixie

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: checkingMousedownDuration

Post by jmburnod » Tue Jul 03, 2012 7:13 pm

Dixie,

Sorry i'm not clear.
I want 2 messages for one mousedown.
If the user keep the mousedown < 2 seconds the script send "doMes1"
If the user keep the mousedown > 2 seconds the script send "doMes2"

Thank one more for your time
Be well

Jean-marc
https://alternatic.ch

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: checkingMousedownDuration

Post by Dixie » Tue Jul 03, 2012 7:18 pm

Jean-Marc...

That's what the script does !... as you can't determine the length of time the mouse has been down until it has been released ?!.. replace the answer command with the name of the handler to go to ...

Code: Select all

local tStart

    on mouseDown
       put the millisecs into tStart
    end mouseDown

    on mouseUp
       put the millisecs - tStart into theTimeTaken
       if theTimeTaken > 2000 then
          domess1
       else
          domess2
       end if
    end mouseUp
EDIT: well, I suppose you can determine the length of time the mouse has been down if you employ mouseStillDown...

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: checkingMousedownDuration

Post by jmburnod » Tue Jul 03, 2012 8:03 pm

Dixie...
Yes, you're right but i want the same result without mouseup

For example:
if the user clic before 2 seconds DoMes1 put the name of the target into a fld

If the user keep the mouse down 2 seconds the DoMes2 show a group
and the user can choose a control of this group without mouseup. The mouseup
is sent by the choosed control of the group.

Jean-Marc
https://alternatic.ch

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

Re: checkingMousedownDuration

Post by bn » Tue Jul 03, 2012 9:08 pm

Hi Jean-Marc,

I know you have special reasons to do things differently at times.

here is a way to do this just on mouseDown, essentially what Dixie did, just without mouseUp.

Code: Select all

local sStartTime

on mouseDown
   put the milliseconds into sStartTime
   send "checkMouse" to me in 0 milliseconds
end mouseDown

on checkMouse
   if the mouse is up then
      if the milliseconds - sStartTime < 2000 then
         set the backgroundcolor of grc 1 to red
      else
         set the backgroundColor of grc 1 to blue
      end if
      exit checkMouse
   end if
   if "checkMouse" is not in the pendingMessages then
      send "checkMouse" to me in 16 milliseconds
   end if
end checkMouse
obviously you would want to change the conditional.

Kind regards
Bernd

Edit: if you don't want to let mouseUp or mouseRelease travel up the message hierarchy then you would have to add

Code: Select all

on mouseUp
end mouseUp
on mouseRelease
end mouseRelease
to your handler

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: checkingMousedownDuration

Post by jmburnod » Tue Jul 03, 2012 10:12 pm

Hi Bernd,
Thanks
That confirm the pendingmessage is the best way for me.

Best regards

Jean-Marc
Attachments
CheckingMousedownDuration001.livecode.zip
(2.64 KiB) Downloaded 192 times
https://alternatic.ch

Post Reply