xdotool: scroll up or down


Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for a way to be able to scroll half a page, preferably by using a key combination like shift page up/down. In Windows, this is doable via autohotkey, for OS there does not seem to be any as easy solution as all I found was this.

I just switch to using Ubuntu 14.04 (from win7). From googling around it seems to me that the easiest way to achieve this is by creating a couple of xdotool/xbindkeys scripts, which emulate half a page worth of mouse scrolling or arrow clicking up and down, respectively. Then I would bind these to custom hotkeys.

However, since I just switched to Ubuntu, I realize that I might be missing something. Therefore I wonder, which is your preferred way to enable half page scrolling in Linux?

Update: I created a script, which emulates scrolling the mousewheel a few times:

#!/bin/bash
xdotool click 4
xdotool click 4
xdotool click 4
xdotool click 4

It works decently, but two problems remain:

  1. It always scrolls the window where the mouse is. I have tried to make it scroll the active window but no luck.

  2. Since it sends mouse wheel scrolls, these are interpreted by other programs such that I cannot have control as a hotkey, because then it zooms. This is a problem in programs where all hotkeys are taken so ideally, I would like to specify the scrolling distance without emulating mouse wheel scrolling.

asked Apr 21 at 16:11
cheflo
136211
add comment

1 Answer

I finally came up with a solution that works very well for most of my use-cases. Using xdotools, I created two scripts, one for scrolling in each direction. This is the script for scrolling down (to scroll up, substitute '5' for '4').

#!/bin/bash

#Get active window id
win=`xdotool getactivewindow`

#Move the mouse to the active window
xdotool mousemove --window $win 45 110 

#Scroll active window several times
xdotool click --clearmodifiers 5
xdotool click --clearmodifiers 5
xdotool click --clearmodifiers 5
xdotool click --clearmodifiers 5
xdotool click --clearmodifiers 5
xdotool click --clearmodifiers 5
xdotool click --clearmodifiers 5
xdotool click --clearmodifiers 5
xdotool click --clearmodifiers 5
xdotool click --clearmodifiers 5
xdotool click --clearmodifiers 5

#Send click to specific window. Finicky.
#xdotool click --window $win 5

Basically, xdotools get the activewindow id and then moves the moves there before sending the mouse scroll signal several times. I could not get it to work by directly specifying which window to send the clicks to, so I solved it by moving the mouse cursor instead. Since Linux automatically scrolls the window under the mouse, this solves problem 1 listed in my question. The --clearmodifiers parameter releases whatever modifier key used in the hotkey combination so that the only key that is sent is the one from xdotool, this solves problem number 2 for me.

The only minor annoyance left is that in some windows, there are multiple panels and with this script I can only scroll the top leftmost panel. This is not a problem when browsing but for IDEs such as spyder. So if someone has a better approach, please share!

answered Apr 21 at 20:55
cheflo
136211
add comment

Your Answer

 

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Stack Exchange

Post as a guest

Name
Email

By posting your answer, you agree to the privacy policy and terms of service.

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

asked

11 days ago

viewed

35 times

active

11 days ago

Community Bulletin

event

Technology Life / Arts Culture / Recreation Science Other
  1. Stack Overflow
  2. Server Fault
  3. Super User
  4. Web Applications
  5. Ask Ubuntu
  6. Webmasters
  7. Game Development
  8. TeX - LaTeX
  1. Programmers
  2. Unix & Linux
  3. Ask Different (Apple)
  4. WordPress Development
  5. Geographic Information Systems
  6. Electrical Engineering
  7. Android Enthusiasts
  8. Information Security
  1. Database Administrators
  2. Drupal Answers
  3. SharePoint
  4. User Experience
  5. Mathematica
  6. more (14)
  1. Photography
  2. Science Fiction & Fantasy
  3. Graphic Design
  4. Seasoned Advice (cooking)
  5. Home Improvement
  6. Personal Finance & Money
  7. Academia
  8. more (10)
  1. English Language & Usage
  2. Skeptics
  3. Mi Yodeya (Judaism)
  4. Travel
  5. Christianity
  6. Arqade (gaming)
  7. Bicycles
  8. Role-playing Games
  9. more (21)
  1. Mathematics
  2. Cross Validated (stats)
  3. Theoretical Computer Science
  4. Physics
  5. MathOverflow
  6. more (7)
  1. Stack Apps
  2. Meta Stack Exchange
  3. Area 51
  4. Stack Overflow Careers
site design / logo © 2014 stack exchange inc; user contributions licensed under cc by-sa 3.0 with attribution required
rev 2014.4.30.1585