Save current mouse position to a variable

It is possible to save the current mouse position to a variable? I've looked everywhere and just can't find a solution. I could use the restore saved mouse position action if I didn't need to drag with LMB to that position...
Any ideas?

I'm looking for this, too! (I'm trying to replicate rectangle pro functionality) - did you ever find a way to do this?

1 Like

What exactly are you trying to do?
When using the "Save Current Mouse Position" action, the mouse position is saved in the variable saved_mouse_position however in the system standard point format: e.g. {610.19921875, 461.64453125}

I'd like to be able to perform a left click & drag action from a certain spot to the saved position. Is it possible to do currently?

you can probably achieve this, but it requires some java script.
First add a "start mouse drag" action, then add a run java script action and finally add a "stop mouse drag" action.

The Java Script can look like this. It gets the saved mouse position and then executes the "Drag Mouse To Position" action.


(async ()=> {
let savedX = await get_number_variable('saved_mouse_position_x');
let savedY = await get_number_variable('saved_mouse_position_y');
let actionDefinition = {

    "BTTPredefinedActionType" : 285,
    "BTTAdditionalActionData" : {
      "BTTMouseMoveX" : savedX,
      "BTTMouseMoveY" : savedY * -1,
      "BTTMouseMoveAnchor" : 0,
      "BTTMouseMoveUnitX" : 0,
      "BTTMouseMoveUnitY" : 0
    }
  };

await trigger_action({json: JSON.stringify(actionDefinition), wait_for_reply: true});

returnToBTT(`${savedX} - ${savedY}`);

})();
1 Like

Hey @Andreas_Hegenberg!
First time here, not sure what the etiquette is around creating new topics vs. adding to existing ones, so apologies if this should be its own new thread, but since it's on topic it might make more sense to group all infos here.

I too was looking to save the mouse position to a variable, and found this thread. I've used the script you shared above, which works great. Thanks!

However, I'm noticing what seems to be either an either an issue in the app, or user error on my part.

My goal was to:

  • Save the mouse position
  • Move the mouse to a specific position
  • {other actions}
  • Restore the original mouse position

However, the position of the mouse gets restored to where it was moved to, not where it was initially.

Am I doing this the wrong way, or does the move mouse action manipulates the same variables? (which would explain what I'm seeing)

Thanks,