UserInput Mouseup and Doublemouseup

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

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: UserInput Mouseup and Doublemouseup

Post by Mag » Fri Nov 08, 2013 8:58 pm

Just tested in iOS and it doesn't work. In desktop works fine.
wait 20
if the mouseClick then
answer "beep 2"
--doDoubleStuff
else
answer "beep 1"
--doSingleStuff
end if

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7247
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: UserInput Mouseup and Doublemouseup

Post by jacque » Fri Nov 08, 2013 9:30 pm

Can't speak for iOS, but in Craig's original handler you could get a more reliable and usually faster response if you test for the doubleClickInterval rather than the hard-coded "20". Twenty ticks is a fair amount of delay, the default doubleclick interval is only about 8 ticks. Since the interval can be set by the developer, 20 may be too short or too long, but testing the doubleClickInterval should give the fastest allowable responses.

Code: Select all

wait the doubleclickinterval milliseconds
if the mouseClick then
-- etc
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: UserInput Mouseup and Doublemouseup

Post by Mag » Sat Nov 09, 2013 12:18 am

Hi Jacque, interesting considerations.

PS
Anyway the problem with iOS is that just don't work the code, maybe it's a bug.
Attachments
Screen Shot.png

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: UserInput Mouseup and Doublemouseup

Post by Mag » Sat Nov 09, 2013 12:20 am

Here is the stack.
Attachments
mouseClick.livecode.zip
(1.43 KiB) Downloaded 170 times

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7247
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: UserInput Mouseup and Doublemouseup

Post by jacque » Sat Nov 09, 2013 8:20 pm

Interesting. Error 252 is "error in if-then condition" and error 624 is "wait aborted". I don't know if that's a bug or a technical limitation. It's odd though because it implies that the check for a mouse click is happening before the wait completes.

You can find the LiveCode Error Lookup stack in the User Samples area. It's a convenient way to find what those cryptic numbers mean when you're debugging. Errors are listed with the most recent one at the top, with the error chain leading up to it listed in reverse order underneath. The first number in each line is the error code to look up; the second number is the line number of the script where the error occured, the third is the character position. So, error 252 is the if-then error, which occurs on line 4 of the script at character 1. (If it's character 1, it usually means the line can't be processed at all.) The top-most error is the one that finally caused the script to stop ("wait aborted.")

I generally avoid the whole double-click issue by not assigning both mouseUp and mouseDoubleUp handlers to the same object. Is that possible in your stack design?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: UserInput Mouseup and Doublemouseup

Post by Mag » Sat Nov 09, 2013 9:19 pm

Hi jacque, thank you so much for the very useful info, I really love be able now to read the errors! I will download the errors stack.

PS
Unfortunately in this case not, I'm creating a mobile app with an image gallery, where user aspects that a single tap hides and shows the navBar and the toolBar; a double-tap switch the image between actual size and full screen.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7247
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: UserInput Mouseup and Doublemouseup

Post by jacque » Sat Nov 09, 2013 10:24 pm

I haven't tested this much but you could tinker with something like this:

Code: Select all

local sFlag

on mouseUp
  put true into sFlag
  send "mouseUpStuff" to me in the doubleClickInterval milliseconds
end mouseUp

on mouseDoubleUp
  put false into sFlag
  -- doubleUp stuff here
end mouseDoubleUp

on mouseUpStuff
  if sFlag = true then
    -- mouseUp stuff here
  end if
end mouseUpStuff
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: UserInput Mouseup and Doublemouseup

Post by Mag » Sun Nov 10, 2013 5:58 pm

Thank you Jacqueline, I will try it right now!

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Location: Plymouth, UK
Contact:

Re: UserInput Mouseup and Doublemouseup

Post by dave.kilroy » Tue Nov 26, 2013 7:17 pm

Craig - thanks for this trick :)
dunbarx wrote:I have alsways used the old HC method:

on mouseup
wait 20
if the mouseClick then
beep 2
--doDoubleStuff
else
beep 1
--doSingleStuff
end if
end mouseUp

This old fashioned method bypasses the issues that putting a mouseUp and a mouseDoubleUp handler in the same script.

I have even extended this to allow triple clicks (and beyond).

Craig Newman
"...this is not the code you are looking for..."

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: UserInput Mouseup and Doublemouseup

Post by Mag » Tue Nov 26, 2013 8:19 pm

jacque wrote:I haven't tested this much but you could tinker with something like this:

Code: Select all

local sFlag

on mouseUp
  put true into sFlag
  send "mouseUpStuff" to me in the doubleClickInterval milliseconds
end mouseUp

on mouseDoubleUp
  put false into sFlag
  -- doubleUp stuff here
end mouseDoubleUp

on mouseUpStuff
  if sFlag = true then
    -- mouseUp stuff here
  end if
end mouseUpStuff
Works nice, thank you jacque!

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: UserInput Mouseup and Doublemouseup

Post by Mag » Thu Feb 20, 2014 2:56 am

... and... If I wanted to create a field that accepts only two characters, and I wanted to wait to see if the user type 1 or 2 keys before placing them in the field? This is even more difficult isn't it?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9689
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: UserInput Mouseup and Doublemouseup

Post by dunbarx » Thu Feb 20, 2014 6:07 am

This wins the bronze for kluges. As an experiment, make a button and a field. Name the field "F1". In the button script:

Code: Select all

on mouseUp
   put "" into fld "f1"
     set the singleChar of fld "f1" to ""
end mouseUp
In the field script:

Code: Select all

on keydown var
   if the singleChar of me = ""  then
      set the singleChar of me to var
      select text of me
   else 
      put the singleChar of me & var into me
      set the singleChar of me to ""
   end if
end keydown
Now this works, but gets constipated easily. Too much finagling in the guts. But maybe it will give you evil ideas.

Craig

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: UserInput Mouseup and Doublemouseup

Post by Mag » Thu Feb 20, 2014 9:56 pm

Very interesting, now we need a way to register a interval so that you understand when the user wants to enter only one digit instead of two...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9689
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: UserInput Mouseup and Doublemouseup

Post by dunbarx » Thu Feb 20, 2014 10:18 pm

I hear rumblings in the gut.

With this sort of required functionality, perhaps it might be better to display an "ask" dialog, where it says:

"Enter two characters..."

And then when the user clicks "OK" you can validate the string and take the appropriate action, either to load the field, or to excoriate the user.

Craig

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: UserInput Mouseup and Doublemouseup

Post by Mag » Thu Feb 20, 2014 11:27 pm

Yes, or maybe with a beep.

I think, however, your idea to store the first key can grow up and become the solution. Maybe with something like this:

I store the first key.
If it do not arrive another press key within a specified time.
Send key in the field.
Otherwise, sends the two keys in the field.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”