How to bind Alt+Arrows to PageUp/PageDown?

Solution 1:

Install xbindkeys and xte:

sudo apt-get install xbindkeys xautomation

Next we need to find the key mappings for Alt+Arrow.

Run xbindkeys -k and press Alt plus whatever arrow key you want. For Alt+Up Arrow I get:

"NoCommand"
m:0x18 + c:111
Alt+Mod2 + Up

Now that we know what the bindings for our keys are we need to create the .xbindkeys configuration file. Run:

touch .xbindkeysrc
gedit .xbindkeysrc

touch creates the file and gedit opens it. Now add:

"xte 'key Page_Up'"
m:0x18 + c:111
Alt+Mod2 + Up

To the file and save it. This will bind Alt+Up Arrow to PgUp.

The basic syntax for xbindkeys is:

"command to run (in quotes)"
keysym of key

Your complete file should look almost identical to this:

"xte 'key Page_Down'"
m:0x18 + c:116
Alt+Mod2 + Down  

"xte 'key Page_Up'"
m:0x18 + c:111
Alt+Mod2 + Up  

Now add xbindkeys to "Startup Applications" to make it run when you boot your computer.
Click 'Add' and put /usr/bin/xbindkeys in the 'Command' field.

enter image description here

Click 'Add' again and reboot.

Solution 2:

I read this https://help.ubuntu.com/community/KeyboardShortcuts which helped me figure out the following. While the xautomation package that includes the xte tool might be used instead of xvkbd to emit the key codes I used xvkbd to do the same thing.

sudo apt-get install xbindkeys xbindkeys-config xvkbd

xbindkeys --defaults > /home/your-user-name/.xbindkeysrc

For some reason this added a binding for ctrl-f that I had to comment out. While perhaps a useful default example I need ctrl-f to find inside of web pages.

After figuring out the "keysims" of Prior for PgUp and Next for PgDown this wasn't too tough. Running and using xbindkeys-config resulted in the following entries in .xbindkeysrc for me.

#alt-up
"xvkbd -xsendevent -text "\[Prior]""
    m:0x18 + c:111
    Alt+Mod2 + Up

#alt-down
"xvkbd -xsendevent -text "\[Next]""
    m:0x18 + c:116
    Alt+Mod2 + Down

when using Ubuntu 12.04 precise pangolin after creating the .xbindkeysrc file it was detected and the xbindkeys program was run automatically on my next login.

The same will work for ctrl.

#ctrl-up
"xvkbd -xsendevent -text "\[Prior]""
    m:0x14 + c:111
    Ctrl+Mod2 + Up

#ctrl-down
"xvkbd -xsendevent -text "\[Next]""
    m:0x14 + c:116
    Ctrl+Mod2 + Down