mouseloc & multitouch

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
rinzwind
Posts: 135
Joined: Tue May 01, 2012 10:44 am

mouseloc & multitouch

Post by rinzwind » Wed Sep 16, 2015 11:07 pm

in the handler for mouseDown or touchDown...
how do I get the x and y coordinate of all touches? The mouseloc only returns the first finger down, not the second. The target only returns the control below the finger... not the exact x and y.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4002
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: mouseloc & multitouch

Post by bn » Wed Sep 16, 2015 11:42 pm


rinzwind
Posts: 135
Joined: Tue May 01, 2012 10:44 am

Re: mouseloc & multitouch

Post by rinzwind » Thu Sep 17, 2015 7:38 am

nope there they use the target.. which is one of 9 buttons. Not exact x and y...

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4002
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: mouseloc & multitouch

Post by bn » Thu Sep 17, 2015 8:49 am

there is a touchMove associated with touchStart.

I tried this on a device:

in the card script of a stack with one locked field that has its focusable unchecked (so that the keyboard does not pop up)

put this script

Code: Select all

local sTouchID1, sTouchID2

on touchStart tTID
   if sTouchID1 = "" then
      put tTID into sTouchID1
   else
      put tID into sTouchID2
   end if
end touchStart

on touchMove tTID, x,y
   if tTID = sTouchID1 then
      put tTID && x,y into line 1 of field 1
   else
      put tTID && x,y into line 2 of field 1
   end if
end touchMove

on touchEnd tTID
   if tTID = sTouchID1 then
      put "" into sTouchID1
   end if
   if tTID = sTouchID2 then 
      put "" into sTouchID2
   end if
end touchEnd
this is just quick and dirty and you would have to refine it. But in my testing it gives me the location of both touches.

Kind regards
Bernd

rinzwind
Posts: 135
Joined: Tue May 01, 2012 10:44 am

Re: mouseloc & multitouch

Post by rinzwind » Thu Sep 17, 2015 9:20 am

aha so touchMove is also send when a touch starts (or isnt moved ;)). That helps. Still would be nice if mousePos would include multitouch support or if x and y are supplied to touchStart/touchEnd.
Thanks!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4002
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: mouseloc & multitouch

Post by bn » Thu Sep 17, 2015 8:17 pm

this is fun,

try this with the same setUp as above: one locked and non-focusable field on a card

the card script:

Code: Select all

local sTouchArray

on touchStart tTID
   put "" into sTouchArray[tTID]
end touchStart

on touchMove tTID, x,y
   put x,y into sTouchArray[tTID]
   upDateField
end touchMove

on touchEnd tTID
   delete variable sTouchArray[tTID]
   upDateField
end touchEnd

on touchRelease tTID
   delete variable sTouchArray[tTID]
   upDateField
end touchRelease

private command upDateField
   put the keys of sTouchArray into tKeys
   sort tKeys ascending numeric
   put "" into tCollect
   repeat for each line aKey in tKeys
      put aKey & tab & sTouchArray[aKey] & return after tCollect
   end repeat
   delete last char of tCollect
   put tCollect into field 1
end upDateField
it shows you all your current fingers. But as soon as you initiate a system gesture it will cancel your touches.

the use of "private command upDateField" instead of "on updateField" is because private command is a tad faster than the other form. -> dictionary private.

Of course you would have to test it on a device. Use both hands also.... Make the field a bit taller.

Kind regards
Bernd

Post Reply

Return to “iOS Deployment”