Is there a way to get the X,Y locations of the "turtle" CURSOR?

I know how to use getXposition for IU Elements but I need to fetch and store the x,y locations of the arrow cursor.

Is this possible? Does the arrow cursor have a hidden IU element name? other techniques?

Thanks for your help

I don’t think it does! But, I’ll check with the staff!

##Thanks for your help

@jkeays - actually, you can! Here’s a project I spun up to show how it’s done:

onEvent("screen1", "mousemove", function(event) {
    console.log("X: " + event.offsetX + "    Y: " + event.offsetY);

A couple of notes:

  • I used the “mousemove” parameter in the onEvent
  • I typed in “event” as the parameter of the callback function
  • I used the event.offsetX to get the x value and event.offsetY to get the y value
  • Tip: Look at what happens when you console.log just “event” (and also try changing the parameter - keyup, keydown, mousemove, etc.). Lots of things to explore!

Thanks. This will work as a work around but I guess I wasn’t clear in my request. I want a function/method to tell me where the drawing cursor is located as it moves around the screen and draws. In your solution, I have to manually move the mouse which is different than the drawing "turtle/arrow. Thanks so much. Unless we know the name of the IU element of the built in “turtle/arrow” I don’t think there is a solution. Thanks again! Peace!

Ah! I understand now.

Would something like this work where you periodically check the turtle’s location?

var turtleX;
var turtleY;

for(var i=0; i<30; i++){

function getXandY(){
  turtleX = getX();
  turtleY = getY();
  console.log("X: " + turtleX + "    Y: " + turtleY);

You are amazing!

I can’t believe I missed the getX() and getY() functions in Applab. As soon as one of my students asked for this info, I said to myself, there has to be a built function which grabs the location data of the turtle.

Thanks a million!


1 Like