Set Mouse Cursor to Left Center of Currently Active Display With Command/Script

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
1
down vote

favorite












I am trying to figure out how to make a script that operates in the following way:



  1. finds dimensions of the display which the mouse pointer is currently on

  2. moves the mouse pointer to the center of the left edge on that display

  3. I'd like to be able to add command arguments when running the script that would add or subtract to the center left edge position and move the mouse accordingly. For example if I ran:


python3 /path/to/script.py




then the script would place the mouse pointer on left edge of display and in the center of the vertical axis. If I ran this:




python3 /path/to/script.py 10 -10




then the script would place the mouse pointer 10px --> from left edge of screen, and -10px (down) from center of vertical axis.



I'm pretty sure xdotool and python can accomplish this, but I am a complete noob when it comes to programming anything, and even though I found this link, I'm still not sure how to proceed. If anyone feels so kind as to help me out with this, it would be greatly appreciated, but if not then no worries.



If anyone is curious as to why I want to do this: I'm setting up a tablet to use i3wm. I'm creating touch button shortcuts for i3 window management using jgmenu. Jgmenu has an option to launch at the location of the mouse pointer. I would like to use a touchegg gesture to first move the mouse pointer with this script, then launch jgmenu.







share|improve this question
























    up vote
    1
    down vote

    favorite












    I am trying to figure out how to make a script that operates in the following way:



    1. finds dimensions of the display which the mouse pointer is currently on

    2. moves the mouse pointer to the center of the left edge on that display

    3. I'd like to be able to add command arguments when running the script that would add or subtract to the center left edge position and move the mouse accordingly. For example if I ran:


    python3 /path/to/script.py




    then the script would place the mouse pointer on left edge of display and in the center of the vertical axis. If I ran this:




    python3 /path/to/script.py 10 -10




    then the script would place the mouse pointer 10px --> from left edge of screen, and -10px (down) from center of vertical axis.



    I'm pretty sure xdotool and python can accomplish this, but I am a complete noob when it comes to programming anything, and even though I found this link, I'm still not sure how to proceed. If anyone feels so kind as to help me out with this, it would be greatly appreciated, but if not then no worries.



    If anyone is curious as to why I want to do this: I'm setting up a tablet to use i3wm. I'm creating touch button shortcuts for i3 window management using jgmenu. Jgmenu has an option to launch at the location of the mouse pointer. I would like to use a touchegg gesture to first move the mouse pointer with this script, then launch jgmenu.







    share|improve this question






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am trying to figure out how to make a script that operates in the following way:



      1. finds dimensions of the display which the mouse pointer is currently on

      2. moves the mouse pointer to the center of the left edge on that display

      3. I'd like to be able to add command arguments when running the script that would add or subtract to the center left edge position and move the mouse accordingly. For example if I ran:


      python3 /path/to/script.py




      then the script would place the mouse pointer on left edge of display and in the center of the vertical axis. If I ran this:




      python3 /path/to/script.py 10 -10




      then the script would place the mouse pointer 10px --> from left edge of screen, and -10px (down) from center of vertical axis.



      I'm pretty sure xdotool and python can accomplish this, but I am a complete noob when it comes to programming anything, and even though I found this link, I'm still not sure how to proceed. If anyone feels so kind as to help me out with this, it would be greatly appreciated, but if not then no worries.



      If anyone is curious as to why I want to do this: I'm setting up a tablet to use i3wm. I'm creating touch button shortcuts for i3 window management using jgmenu. Jgmenu has an option to launch at the location of the mouse pointer. I would like to use a touchegg gesture to first move the mouse pointer with this script, then launch jgmenu.







      share|improve this question












      I am trying to figure out how to make a script that operates in the following way:



      1. finds dimensions of the display which the mouse pointer is currently on

      2. moves the mouse pointer to the center of the left edge on that display

      3. I'd like to be able to add command arguments when running the script that would add or subtract to the center left edge position and move the mouse accordingly. For example if I ran:


      python3 /path/to/script.py




      then the script would place the mouse pointer on left edge of display and in the center of the vertical axis. If I ran this:




      python3 /path/to/script.py 10 -10




      then the script would place the mouse pointer 10px --> from left edge of screen, and -10px (down) from center of vertical axis.



      I'm pretty sure xdotool and python can accomplish this, but I am a complete noob when it comes to programming anything, and even though I found this link, I'm still not sure how to proceed. If anyone feels so kind as to help me out with this, it would be greatly appreciated, but if not then no worries.



      If anyone is curious as to why I want to do this: I'm setting up a tablet to use i3wm. I'm creating touch button shortcuts for i3 window management using jgmenu. Jgmenu has an option to launch at the location of the mouse pointer. I would like to use a touchegg gesture to first move the mouse pointer with this script, then launch jgmenu.









      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 19 at 14:39









      Joe Millard

      82




      82




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          This approach uses utilities for X servers, it presumably won't work with Wayland.

          Here's a little bash function for you:





          line_up () 
          sed '/Height/!d;s/.* //') / 2 ));
          [[ -n $2 ]] && vc=$(( -$2 + vc ));
          xdotool mousemove $(( $1 )) $vc



          As a oneliner:



          line_up()sed '/Height/!d;s/.* //')/2));[[ $2 ]]&&vc=$((-$2+vc));xdotool mousemove $(($1)) $vc;


          This uses the output of xwininfo to get the current display's height, divides it in half and saves it as variable cv. If $2 exists, it is subtracted. xdotool then moves the cursor to the coordinates $1,$vc. I take advantage of the fact that bash's arithmetic expression just returns 0 if $1 is not set, a plain xdotool mousemove $1 … would just throw an error in that case. As above you can call the function with as much arguments as you like, if there are none it will just move the cursor to 0,totalheight/2, if there's one to $1,totalheight/2 and if there are two or more to $1,totalheight/2-$2.



          Example run



          $ xwininfo -root|sed '/Height/!d' # display height is 1024 px
          Height: 1024
          $ xdotool getmouselocation # current mouse location: 469,875
          x:469 y:875 screen:0 window:15294612
          $ line_up
          $ xdotool getmouselocation # current mouse location: 0,512
          x:0 y:512 screen:0 window:14680366
          $ line_up 10
          $ xdotool getmouselocation # current mouse location: 10,512
          x:10 y:512 screen:0 window:14680366
          $ line_up 20 -10
          $ xdotool getmouselocation # current mouse location: 20,522
          x:20 y:522 screen:0 window:14680366


          Sources



          • How do I find out my screen resolution from a shell script?

          • The Bash Hackers Wiki

          • man xdotool

          • the usual try & error





          share|improve this answer






















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "89"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1026420%2fset-mouse-cursor-to-left-center-of-currently-active-display-with-command-script%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            This approach uses utilities for X servers, it presumably won't work with Wayland.

            Here's a little bash function for you:





            line_up () 
            sed '/Height/!d;s/.* //') / 2 ));
            [[ -n $2 ]] && vc=$(( -$2 + vc ));
            xdotool mousemove $(( $1 )) $vc



            As a oneliner:



            line_up()sed '/Height/!d;s/.* //')/2));[[ $2 ]]&&vc=$((-$2+vc));xdotool mousemove $(($1)) $vc;


            This uses the output of xwininfo to get the current display's height, divides it in half and saves it as variable cv. If $2 exists, it is subtracted. xdotool then moves the cursor to the coordinates $1,$vc. I take advantage of the fact that bash's arithmetic expression just returns 0 if $1 is not set, a plain xdotool mousemove $1 … would just throw an error in that case. As above you can call the function with as much arguments as you like, if there are none it will just move the cursor to 0,totalheight/2, if there's one to $1,totalheight/2 and if there are two or more to $1,totalheight/2-$2.



            Example run



            $ xwininfo -root|sed '/Height/!d' # display height is 1024 px
            Height: 1024
            $ xdotool getmouselocation # current mouse location: 469,875
            x:469 y:875 screen:0 window:15294612
            $ line_up
            $ xdotool getmouselocation # current mouse location: 0,512
            x:0 y:512 screen:0 window:14680366
            $ line_up 10
            $ xdotool getmouselocation # current mouse location: 10,512
            x:10 y:512 screen:0 window:14680366
            $ line_up 20 -10
            $ xdotool getmouselocation # current mouse location: 20,522
            x:20 y:522 screen:0 window:14680366


            Sources



            • How do I find out my screen resolution from a shell script?

            • The Bash Hackers Wiki

            • man xdotool

            • the usual try & error





            share|improve this answer


























              up vote
              1
              down vote



              accepted










              This approach uses utilities for X servers, it presumably won't work with Wayland.

              Here's a little bash function for you:





              line_up () 
              sed '/Height/!d;s/.* //') / 2 ));
              [[ -n $2 ]] && vc=$(( -$2 + vc ));
              xdotool mousemove $(( $1 )) $vc



              As a oneliner:



              line_up()sed '/Height/!d;s/.* //')/2));[[ $2 ]]&&vc=$((-$2+vc));xdotool mousemove $(($1)) $vc;


              This uses the output of xwininfo to get the current display's height, divides it in half and saves it as variable cv. If $2 exists, it is subtracted. xdotool then moves the cursor to the coordinates $1,$vc. I take advantage of the fact that bash's arithmetic expression just returns 0 if $1 is not set, a plain xdotool mousemove $1 … would just throw an error in that case. As above you can call the function with as much arguments as you like, if there are none it will just move the cursor to 0,totalheight/2, if there's one to $1,totalheight/2 and if there are two or more to $1,totalheight/2-$2.



              Example run



              $ xwininfo -root|sed '/Height/!d' # display height is 1024 px
              Height: 1024
              $ xdotool getmouselocation # current mouse location: 469,875
              x:469 y:875 screen:0 window:15294612
              $ line_up
              $ xdotool getmouselocation # current mouse location: 0,512
              x:0 y:512 screen:0 window:14680366
              $ line_up 10
              $ xdotool getmouselocation # current mouse location: 10,512
              x:10 y:512 screen:0 window:14680366
              $ line_up 20 -10
              $ xdotool getmouselocation # current mouse location: 20,522
              x:20 y:522 screen:0 window:14680366


              Sources



              • How do I find out my screen resolution from a shell script?

              • The Bash Hackers Wiki

              • man xdotool

              • the usual try & error





              share|improve this answer
























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                This approach uses utilities for X servers, it presumably won't work with Wayland.

                Here's a little bash function for you:





                line_up () 
                sed '/Height/!d;s/.* //') / 2 ));
                [[ -n $2 ]] && vc=$(( -$2 + vc ));
                xdotool mousemove $(( $1 )) $vc



                As a oneliner:



                line_up()sed '/Height/!d;s/.* //')/2));[[ $2 ]]&&vc=$((-$2+vc));xdotool mousemove $(($1)) $vc;


                This uses the output of xwininfo to get the current display's height, divides it in half and saves it as variable cv. If $2 exists, it is subtracted. xdotool then moves the cursor to the coordinates $1,$vc. I take advantage of the fact that bash's arithmetic expression just returns 0 if $1 is not set, a plain xdotool mousemove $1 … would just throw an error in that case. As above you can call the function with as much arguments as you like, if there are none it will just move the cursor to 0,totalheight/2, if there's one to $1,totalheight/2 and if there are two or more to $1,totalheight/2-$2.



                Example run



                $ xwininfo -root|sed '/Height/!d' # display height is 1024 px
                Height: 1024
                $ xdotool getmouselocation # current mouse location: 469,875
                x:469 y:875 screen:0 window:15294612
                $ line_up
                $ xdotool getmouselocation # current mouse location: 0,512
                x:0 y:512 screen:0 window:14680366
                $ line_up 10
                $ xdotool getmouselocation # current mouse location: 10,512
                x:10 y:512 screen:0 window:14680366
                $ line_up 20 -10
                $ xdotool getmouselocation # current mouse location: 20,522
                x:20 y:522 screen:0 window:14680366


                Sources



                • How do I find out my screen resolution from a shell script?

                • The Bash Hackers Wiki

                • man xdotool

                • the usual try & error





                share|improve this answer














                This approach uses utilities for X servers, it presumably won't work with Wayland.

                Here's a little bash function for you:





                line_up () 
                sed '/Height/!d;s/.* //') / 2 ));
                [[ -n $2 ]] && vc=$(( -$2 + vc ));
                xdotool mousemove $(( $1 )) $vc



                As a oneliner:



                line_up()sed '/Height/!d;s/.* //')/2));[[ $2 ]]&&vc=$((-$2+vc));xdotool mousemove $(($1)) $vc;


                This uses the output of xwininfo to get the current display's height, divides it in half and saves it as variable cv. If $2 exists, it is subtracted. xdotool then moves the cursor to the coordinates $1,$vc. I take advantage of the fact that bash's arithmetic expression just returns 0 if $1 is not set, a plain xdotool mousemove $1 … would just throw an error in that case. As above you can call the function with as much arguments as you like, if there are none it will just move the cursor to 0,totalheight/2, if there's one to $1,totalheight/2 and if there are two or more to $1,totalheight/2-$2.



                Example run



                $ xwininfo -root|sed '/Height/!d' # display height is 1024 px
                Height: 1024
                $ xdotool getmouselocation # current mouse location: 469,875
                x:469 y:875 screen:0 window:15294612
                $ line_up
                $ xdotool getmouselocation # current mouse location: 0,512
                x:0 y:512 screen:0 window:14680366
                $ line_up 10
                $ xdotool getmouselocation # current mouse location: 10,512
                x:10 y:512 screen:0 window:14680366
                $ line_up 20 -10
                $ xdotool getmouselocation # current mouse location: 20,522
                x:20 y:522 screen:0 window:14680366


                Sources



                • How do I find out my screen resolution from a shell script?

                • The Bash Hackers Wiki

                • man xdotool

                • the usual try & error






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Apr 19 at 19:39

























                answered Apr 19 at 19:18









                dessert

                19.8k55594




                19.8k55594



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1026420%2fset-mouse-cursor-to-left-center-of-currently-active-display-with-command-script%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    pylint3 and pip3 broken

                    Missing snmpget and snmpwalk

                    How to enroll fingerprints to Ubuntu 17.10 with VFS491