Xorg Mouse – Emulate Horizontal Scrolling with Shift Key

mousexorg

I want to emulate horizontal scrolling when I use my (vertical) scroll wheel and pressing Shift.

In some applications (Chrom{e,ium}) this already works, but I'm looking for a generic solution for X applications.

The closest I got so far is xbindkeys + xdotool.

# ~/.xbindkeysrc
"xdotool click 6"
  shift + b:4

"xdotool click 7"
  shift + b:5

The Problem is that xbindkeys seems to miss some events, and occasionally a vertical scroll "gets through". This is very annoying. It looks like xbindkeys is using some kind of polling?

Also I don't like spawning hundreds of shell commands per seconds.

I got a small screen and have to scroll horizontally a lot.

How can I achieve generic horizontal scrolling?

UPDATE:

There is another way that does mostly what I want with xbindkeys and xmodmap.

"xmodmap -e 'pointer = 1 2 3 6 7 4 5 8 9 10'"
  c:50
"xmodmap -e 'pointer = default'"
  release + shift + c:50

When Shift is held, the pointer buttons 4 and 5 are mapped to 6 and 7. (Buttons 4/5 are fore vertical scrolling and 6/7 for horizontal scrolling). c:50 is the left Shift key. On key release the default pointer mapping is restored.

This solves the "too many events" Problem nicely. However, the Shift key doesn't work as normal modifier anymore. I tried to re-issue the Shift press/release events with xdotool like this:

"xmodmap -e 'pointer = 1 2 3 6 7 4 5 8 9 10';  xdotool keydown Shift_L"
  c:50
"xmodmap -e 'pointer = default';  xdotool keyup Shift_L"
  release + shift + c:50

According to xev the Shift events get through, but I think it's not recognized as a modifier any more. For example, pressing Shift+A wouldn't produce an uppercase A.

Best Answer

I found an acceptable solution for me.

I didn't find a way to use Shift or any other key as my modifier to rotate the wheel axis as long as it is pressed.

I'm now using a simple .xbindkeysrc with a toggle button:

"~/toggle.sh"
  alt + x

The toggle.sh script looks like this:

#!/bin/sh
on()
{
  xmodmap -e 'pointer = 1 2 3 6 7 4 5 8 9 10'
}

off()
{
  xmodmap -e 'pointer = default'
}

if xmodmap -pp | grep -q '4.*6'; then
  off
else
  on
fi

This allows me to toggle the behaviour. When I press Alt + X, my mouse wheel axis is rotated, and when I press it again, it's set to the default.

That should work for now.

If someone finds a way to do it with Shift as a "modifier" (mouse axis rotate as long as it's pressed), please let me know.

EDIT: As Alt+x is a commonly used hotkey, I changed it to:

(xbindkey '(control "b:3") "toggle-wheel.sh")

(I switched to guile configuration so the above should be in a file named .xbindkeysrc.scm)

This will toggle the scroll wheel direction with Ctrl + right mouse button.

Related Question