Is there a way to send a global touch event at an x and y location and have it touch whaterver is there?

I’m looking to create a debugger for my app and I would like the debugger to live outisde the code not really integrated within in. I would like to have a few files and when required in the main will tap on various places of the app. 

When a user touches the screen does corona send off a global event and whatever is within that x and y gets the touch event or is it more complex than that?

Read here:

https://docs.coronalabs.com/guide/events/touchMultitouch/index.html

The touch passes through (and is intercepted by) all display objects at the touch point; front most to back most.

If you want to log touch points use a runtime touch handler to log the x,y and return false to allow the touch to propagate.

If you want to simulate touches then this post might help you - https://forums.coronalabs.com/topic/56747-simulating-touching-screen/

I understand how touch and tap events work and their propagation. I’m more so trying to figure out the best way to just simulate a touch event without a user touching the screen. I can crate the table of data to send but where and how do I send it? Do I send it to the the runtime, the stage etc etc? Also how would I send the event so the listener would see it?

Edit: Actually Robs post in that link you sent said it’s not as simple as just sending the x and y I’d have to traverse all the objects and groups to see what is within the x and y. That’s way more work then I wanted to put into this little debugger. I can just use adb to send tap events that will be way easier. 

It sounds like you want to inject a simulated touch and see what would be hit.  That can’t be done in the way you’re wanting to.

Assuming you are using table listeners and not runtime listeners,  you’ll have to reverse-iterate over the hierarchy of objects and groups at that position and directly call the object’s touch listener.

  1. Start at display.currentStage (group 0),

  2. Dig up into any children groups of group 0, group 1, group 2, …

  3. When you find yourself at the top of the hierarchy, iterate over the children of the top-most group from numchildren to 1

  4. For each object, check to see if <x,y> is in the bounds of the object and if it has a touch listener.  If so, call the touch listener.

  5. Continue this for each object in the top group, then the parent groups, until the touch listener returns true or until you reach the last object in display.currentStage

Tip: You’ll need to be able do distinguish groups/containers from other display objects.  If you use SSK2, it automatically marks display groups and containers as:

  • display groups w/ SSK:
    • obj.__isGroup == true  
    • obj.__isContainer == false
  • display containers w/ SSK:
    • obj.__isGroup == true  
    • obj.__isContainer == true

If you go the ADB route, could you share some details on how you did that?  I’m always up to learn something new.

Amazon also has a testing tool that does unit testing by tapping the screen.  There does seem to be a bit of common sense to it - e.g. it always seems to know where my “skip tutorial link is”.

Sure, it’s actually really simple. I’m doing the following on a mac, but you can easily do it on windows as well

  1. Download adb and appt and put them in your root user on your mac i.e. ~/
  2. Place the script.command and the apk you want to test on in the same folder
  3. Chmod the script to 777
  4. Make sure your phone is plugged into your computer (you can do it over tcpip as well but it’s much slower)
  5. Double tap the script and watch it do its thing

~/adb shell input tap X Y   #adb tap event
~/adb shell input touchscreen swipe X1 Y1 X2 Y2 DURATION    #adb swipe event

1 huge gotcha is the fact that adb uses x and y of the device based on various factors. So if you setup a test and it works perfectly on 1 device more then likely all the touch points will be off on a different device. Ohh and to get the X / Y locations turn on developer options on the device and enable show touches. Now when you tap you will be able to quickly get the X / Y of the tap.

 

#!/bin/bash DIR="$( cd "$( dirname "${BASH\_SOURCE[0]}" )" && pwd )" cd "$DIR"; for i in "$DIR"/\*.apk; do ~/adb install -r "$i"; pkg=$(~/aapt dump badging "$i"|awk -F" " '/package/ {print $2}'|awk -F"'" '/name=/ {print $2}') act=$(~/aapt dump badging "$i"|awk -F" " '/launchable-activity/ {print $2}'|awk -F"'" '/name=/ {print $2}') ~/adb shell am start -n $pkg/$act name=`~/adb shell dumpsys activity activities | grep mFocusedActivity | cut -d . -f 5 | cut -d ' ' -f 1` #Make sure we're still in the game "ansca" is corona sdk apps echo $name if ["$name" == 'ansca'] || ["$name" == 'corona']; then #create folder name based on apk name fname="${i}" replaceText="" fname=${fname/.apk/$replaceText} #change path NEWDIR="$(dirname "${i}")" cd "$NEWDIR" mkdir "${fname}" cd "${fname}" #sleep = pause sleep 10 ######################### NO NEED TO EDIT ANYTHING ABOVE HERE ######################### #----------------------------------- #log-in as guest #----------------------------------- ~/adb shell input tap 906 703 #Play as guest ~/adb shell input tap 398 542 #Hit the back button ~/adb shell input tap 906 703 #Play as guest button ~/adb shell input tap 800 534 #Play as guest red button ~/adb shell input tap 842 440 #Hit the allow permission popup sleep 10 #----------------------------------- #END log-in as guest #----------------------------------- #----------------------------------- #tap on the users avatar and change their name/icon #----------------------------------- ~/adb shell input tap 63 42 #Tap on users avatar sleep 2 ~/adb shell input tap 680 200 #Tap on the username field sleep 3 #Press and hold down on backspace ~/adb shell input touchscreen swipe 1200 515 1200 515 5 #Type the name dave ~/adb shell input tap 362 600 #the letter d ~/adb shell input tap 158 600 #the letter a ~/adb shell input tap 531 676 #the letter v ~/adb shell input tap 324 512 #the letter e ~/adb shell input tap 1160 600 #the done button sleep 2 ~/adb shell input tap 985 614 #Tap on an avatar ~/adb shell input tap 1075 480 #Tap on next page button ~/adb shell input tap 1075 480 #Tap on next page button ~/adb shell input tap 985 614 #Tap on an avatar #take a screenshot of the main scene ~/adb shell screencap -p /mnt/sdcard/avatar.png ~/adb pull /mnt/sdcard/avatar.png ~/adb shell input tap 1196 45 #Close avatar page sleep 10 #----------------------------------- #END tap on the users avatar and change their name/icon #----------------------------------- #~/adb shell input touchscreen swipe 585 212 135, 212 #~/adb shell input tap 350 1475 fi #uninstall app ~/adb uninstall $pkg done

Read here:

https://docs.coronalabs.com/guide/events/touchMultitouch/index.html

The touch passes through (and is intercepted by) all display objects at the touch point; front most to back most.

If you want to log touch points use a runtime touch handler to log the x,y and return false to allow the touch to propagate.

If you want to simulate touches then this post might help you - https://forums.coronalabs.com/topic/56747-simulating-touching-screen/

I understand how touch and tap events work and their propagation. I’m more so trying to figure out the best way to just simulate a touch event without a user touching the screen. I can crate the table of data to send but where and how do I send it? Do I send it to the the runtime, the stage etc etc? Also how would I send the event so the listener would see it?

Edit: Actually Robs post in that link you sent said it’s not as simple as just sending the x and y I’d have to traverse all the objects and groups to see what is within the x and y. That’s way more work then I wanted to put into this little debugger. I can just use adb to send tap events that will be way easier. 

It sounds like you want to inject a simulated touch and see what would be hit.  That can’t be done in the way you’re wanting to.

Assuming you are using table listeners and not runtime listeners,  you’ll have to reverse-iterate over the hierarchy of objects and groups at that position and directly call the object’s touch listener.

  1. Start at display.currentStage (group 0),

  2. Dig up into any children groups of group 0, group 1, group 2, …

  3. When you find yourself at the top of the hierarchy, iterate over the children of the top-most group from numchildren to 1

  4. For each object, check to see if <x,y> is in the bounds of the object and if it has a touch listener.  If so, call the touch listener.

  5. Continue this for each object in the top group, then the parent groups, until the touch listener returns true or until you reach the last object in display.currentStage

Tip: You’ll need to be able do distinguish groups/containers from other display objects.  If you use SSK2, it automatically marks display groups and containers as:

  • display groups w/ SSK:
    • obj.__isGroup == true  
    • obj.__isContainer == false
  • display containers w/ SSK:
    • obj.__isGroup == true  
    • obj.__isContainer == true

If you go the ADB route, could you share some details on how you did that?  I’m always up to learn something new.

Amazon also has a testing tool that does unit testing by tapping the screen.  There does seem to be a bit of common sense to it - e.g. it always seems to know where my “skip tutorial link is”.

Sure, it’s actually really simple. I’m doing the following on a mac, but you can easily do it on windows as well

  1. Download adb and appt and put them in your root user on your mac i.e. ~/
  2. Place the script.command and the apk you want to test on in the same folder
  3. Chmod the script to 777
  4. Make sure your phone is plugged into your computer (you can do it over tcpip as well but it’s much slower)
  5. Double tap the script and watch it do its thing

~/adb shell input tap X Y   #adb tap event
~/adb shell input touchscreen swipe X1 Y1 X2 Y2 DURATION    #adb swipe event

1 huge gotcha is the fact that adb uses x and y of the device based on various factors. So if you setup a test and it works perfectly on 1 device more then likely all the touch points will be off on a different device. Ohh and to get the X / Y locations turn on developer options on the device and enable show touches. Now when you tap you will be able to quickly get the X / Y of the tap.

 

#!/bin/bash DIR="$( cd "$( dirname "${BASH\_SOURCE[0]}" )" && pwd )" cd "$DIR"; for i in "$DIR"/\*.apk; do ~/adb install -r "$i"; pkg=$(~/aapt dump badging "$i"|awk -F" " '/package/ {print $2}'|awk -F"'" '/name=/ {print $2}') act=$(~/aapt dump badging "$i"|awk -F" " '/launchable-activity/ {print $2}'|awk -F"'" '/name=/ {print $2}') ~/adb shell am start -n $pkg/$act name=`~/adb shell dumpsys activity activities | grep mFocusedActivity | cut -d . -f 5 | cut -d ' ' -f 1` #Make sure we're still in the game "ansca" is corona sdk apps echo $name if ["$name" == 'ansca'] || ["$name" == 'corona']; then #create folder name based on apk name fname="${i}" replaceText="" fname=${fname/.apk/$replaceText} #change path NEWDIR="$(dirname "${i}")" cd "$NEWDIR" mkdir "${fname}" cd "${fname}" #sleep = pause sleep 10 ######################### NO NEED TO EDIT ANYTHING ABOVE HERE ######################### #----------------------------------- #log-in as guest #----------------------------------- ~/adb shell input tap 906 703 #Play as guest ~/adb shell input tap 398 542 #Hit the back button ~/adb shell input tap 906 703 #Play as guest button ~/adb shell input tap 800 534 #Play as guest red button ~/adb shell input tap 842 440 #Hit the allow permission popup sleep 10 #----------------------------------- #END log-in as guest #----------------------------------- #----------------------------------- #tap on the users avatar and change their name/icon #----------------------------------- ~/adb shell input tap 63 42 #Tap on users avatar sleep 2 ~/adb shell input tap 680 200 #Tap on the username field sleep 3 #Press and hold down on backspace ~/adb shell input touchscreen swipe 1200 515 1200 515 5 #Type the name dave ~/adb shell input tap 362 600 #the letter d ~/adb shell input tap 158 600 #the letter a ~/adb shell input tap 531 676 #the letter v ~/adb shell input tap 324 512 #the letter e ~/adb shell input tap 1160 600 #the done button sleep 2 ~/adb shell input tap 985 614 #Tap on an avatar ~/adb shell input tap 1075 480 #Tap on next page button ~/adb shell input tap 1075 480 #Tap on next page button ~/adb shell input tap 985 614 #Tap on an avatar #take a screenshot of the main scene ~/adb shell screencap -p /mnt/sdcard/avatar.png ~/adb pull /mnt/sdcard/avatar.png ~/adb shell input tap 1196 45 #Close avatar page sleep 10 #----------------------------------- #END tap on the users avatar and change their name/icon #----------------------------------- #~/adb shell input touchscreen swipe 585 212 135, 212 #~/adb shell input tap 350 1475 fi #uninstall app ~/adb uninstall $pkg done