Set Mouse Cursor to Left Center of Currently Active Display With Command/Script
up vote
1
down vote
favorite
I am trying to figure out how to make a script that operates in the following way:
- finds dimensions of the display which the mouse pointer is currently on
- moves the mouse pointer to the center of the left edge on that display
- 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.
bash scripts mouse
add a comment |Â
up vote
1
down vote
favorite
I am trying to figure out how to make a script that operates in the following way:
- finds dimensions of the display which the mouse pointer is currently on
- moves the mouse pointer to the center of the left edge on that display
- 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.
bash scripts mouse
add a comment |Â
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:
- finds dimensions of the display which the mouse pointer is currently on
- moves the mouse pointer to the center of the left edge on that display
- 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.
bash scripts mouse
I am trying to figure out how to make a script that operates in the following way:
- finds dimensions of the display which the mouse pointer is currently on
- moves the mouse pointer to the center of the left edge on that display
- 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.
bash scripts mouse
asked Apr 19 at 14:39
Joe Millard
82
82
add a comment |Â
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
edited Apr 19 at 19:39
answered Apr 19 at 19:18
dessert
19.8k55594
19.8k55594
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password