Scrolling on FreeBSD with the arrow keys

I recently acquired a HP EliteBook 9470m (before you ask: it's personal), and installed FreeBSD on it. The Synaptics touchpad is detected on FreeBSD as a PS/2 mouse on both laptops, and unlike the 2570p I was coming from, the 9470m doesn't automatically fallback to edge scrolling. While web browsers make up by making it easy to scroll with the arrow keys, other applications (such as email) end up doing actions you might not want with the arrow keys.

Here comes (not to be confused with the jQuery plugin Scrollify). It works alongside xbindkeys to emulate scrolling with the up/down keys.

Since is not yet on FreeBSD Ports, you will have to install it manually.


First, you need py-xlib and pip. To install this, run either:

pkg install py27-pip py27-xlib


cd /usr/ports/devel/python-pip
make config-recursive install clean
cd /usr/ports/x11-toolkits/py-xlib
make config-recursive install clean

in a root shell.

Then you need to install the Python module pynput. This is used for controlling the keyboard and mouse from Python, and is not in Ports either. To install this, run this as a normal user:

pip install --user pynput

Next, you will need xbindkeys in order to do the mapping. To install this, run:

pkg install xbindkeys


cd /usr/ports/x11/xbindkeys
make config-recursive install clean

Finally, you should install somewhere on your system. For example, if you want it in ~/.local/bin:

mkdir -p ~/.local/bin
cd ~/.local/bin
fetch --no-verify-peer


You will need to modify .xbindkeysrc. To do that, run:

vim ~/.xbindkeysrc

and add the following:

"python2.7 ~/.local/bin/ up"
  alt + Up

"python2.7 ~/.local/bin/ down"
  alt + Down

Replace vim with your text editor of choice, ~/.local/bin to the place you stored, and alt + Up and alt + Down to your desired key combination (you can Google search the possible combinations). This will map the scroll up to Alt + Up and scroll down to Alt + Down.

You finally need to make your window manager or desktop environment (GNOME for me) launch xbindkeys on startup. For instance, on GNOME, make the directory ~/.config/autostart if it doesn't exist, create a .desktop file in the directory with the following content:

[Desktop Entry]
GenericName=Keyboard Bindings

Copy the .desktop file you created to ~/.local/applications. This ensures that GNOME (or whatever DE you use) can see the startup script.

On your specific WM or DE, this can be found on the Internet. Arch Linux's wiki has a page on startup scripts for all the major DEs (and I believe the information should be common on FreeBSD as well). Keep in mind that there is a delay (~1sec) when scrolling with this method.

I may update this page once or pynput makes it to FreeBSD Ports (I am a maintainer), but in the meanwhile, that's it.

Also, for the JavaScript hipsters: no, I'm not going to join you and become a 'web developer'. I tried many years ago, but I don't think it's really 'me'.


UPDATE: An update to pynput has broke FreeBSD. The error I get is:

Traceback (most recent call last):
  File "/home/neel/.local/bin/", line 20, in <module>
    mouse.scroll(0, scroll_amt)
  File "/home/neel/.local/lib/python2.7/site-packages/pynput/mouse/", line 78, in scroll
    self._scroll(dx, dy)
  File "/home/neel/.local/lib/python2.7/site-packages/pynput/mouse/", line 75, in _scroll
    self._check_bounds(dx, dy)
  File "/home/neel/.local/lib/python2.7/site-packages/pynput/mouse/", line 103, in _check_bounds
    raise ValueError()

You can track the bug on GitHub.

UPDATE 2: pynput works now. Ignore the first UPDATE message.

UPDATE 3: There is an experimental patch which enables the Synaptics on the 9470m (as as well as other HP EliteBooks with a pointing stick like the 2570p, 8470p, and 840). I also switched my FreeBSD laptop (again) to a EliteBook 1040 G1 (mainly to upgrade to a HiDPI display and an i7 to make compiling FreeBSD Ports faster).

UPDATE 4: I moved the update messages to the bottom.

Also, if you are interested on running FreeBSD on an EliteBook and use 12-CURRENT from January 31, 2018 onwards (or 12.0-RELEASE onwards when it comes out), you get Synaptics support. The SVN commits are as follows:

I will still keep this article up because there may be other laptops where Synaptics (or Elantech) may not be detected properly.

UPDATE 5: Two things:

  • Fix a typo in Update 4.
  • Good news: The patches for the Synaptics on HP EliteBooks have been backported to 11-STABLE and will make it to 11.2.
Show Comments