No internet connection
  1. Home
  2. Support

Mouse Position

By Fabio Capelli @Fabio_Capelli
    2021-03-17 16:41:53.083Z

    Yeay!
    Is there a way to move the mouse horizontally or vertically to the actual position?
    Basically retaining one of the axes and set the other one to a specific distance from let's say one of the edges of the selected UI element?
    I ve tried all the mouse command available but I can't wrap my head around it.

    Basically this is what I am trying to achieve. in Ableton.
    Assuming the mouse is somewhere In the arrange view, over a track. I want the mouse to move horizontally reaching the area where the name of the track is. Which should be about 270 pixels from the right edge of the main Ableton window.

    thank yoU!

    • 5 replies
    1. Hi Fabio,

      Yes - it's possible to get the value of the current mouse position, do some math on it, and then move the mouse to where you want.

      See an example here that tries to do exactly what you requested:

      
      //Get the frame of the Ableton Live main window
      var frame = sf.ui.abletonLive.mainWindow.frame;
      
      //Get the current mouse position
      var mousePos = sf.mouse.getPosition().position;
      
      //Move your mouse accordingly
      sf.mouse.setPosition({
          position: {
              x: frame.x + frame.w - 270,
              y: mousePos.y,
          },
      });
      
      //Note: use sf.mouse.click instead of sf.mouse.setPosition if you just want to click :)
      
      
      1. FFabio Capelli @Fabio_Capelli
          2021-03-17 17:02:31.861Z

          hell yeah!! this will make life so much easier!
          you just saved me at least 1 second worth of mouse clicking :) :)

          Can I add your script to a macro I already have or I would have to convert the macro I already have into a script and only work from the terminal?

          1. This particular script could be called from within a larger macro by just adding the script as an action in your macro (click Add Action and choose the script).

            You would have had to first create this as a stand alone script for that to work.

            1. FFabio Capelli @Fabio_Capelli
                2021-03-19 12:44:37.196Z

                I only have EXECUTE JXA SCRIPT or EXECUTE APPLESCRIPT and they don't work..

                1. To add a script to a package, choose "+ New" and instead of choosing Macro, choose Script.

                  Give the script a name. Then, in the bottom right corner, add the script I sent you above.

                  This is how you make SF scripts.

                  Now, if you want to call that script inside of a Macro, you can add a reference to that script by searching for its name when you click Add Action.

                  I'd highly recommend watching more of our Learning SoundFlow tutorials here - they cover most of this:

                  https://www.youtube.com/playlist?list=PLKWpZOwx5Z3jxnpNo_dQPhDQNRwp7DCNj