3

Is it possible to automatically move the mouse to anywhere in the window that has gained focus by a keystroke?

For example:

  1. There are two monitors.
  2. Mouse is near the left edge of the monitor on the left.
  3. Using Alt+Tab, a window residing at the monitor on the right is switched and you have to move the mouse to this window.
  4. It will be great to move the mouse into this window automatically or at least with a keyboard shortcut.
  • 1
    I suggested that for Unity a long time ago, but there was little interest. I don't know of any such software, although that would be quite nice. – Jo-Erlend Schinstad Nov 2 '14 at 19:38
1

I just had the same need and ended up here looking for a solution to the problem.

As it doesn't seem like something that anybody else solved anywhere else, I used my basic shell skills to create the following script, which does the job using xdotool:

# Get geometry information of the currently active window.
GEOMETRY=`xdotool getwindowgeometry $(xdotool getactivewindow)`                 
# Extract information about the dimensions of the window and divide
# both of them by 2.
DIMENSIONS=$(echo "$GEOMETRY" | grep -Po "[0-9]+x[0-9]+")                       
X=$(echo $DIMENSIONS | sed 's/x[0-9]\+//g')                                     
Y=$(echo $DIMENSIONS | sed 's/[0-9]\+x//g')                                     
X=$(expr $X / 2)                                                                
Y=$(expr $Y / 2)                                                                
# Move the mouse cursor to the middle of the active window.
xdotool mousemove -w $(xdotool getactivewindow) $X $Y

I've put this in a file and added a custom keyboard shortcut that runs it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.