Tablet Hardware Buttons

From ThinkWiki
Revision as of 18:19, 4 January 2013 by Eternallinux (Talk | contribs) (Add section on using xbindkeys to bind the tablet buttons.)
Jump to: navigation, search

Tablet Hardware Buttons

The Thinkpad tablets includes hardware buttons located on the LCD screen bezel. They are designed to be used when the ThinkPad is converted to the tablet configuration (though they are still accessible when in the laptop configuration).

Buttons

The X41 Tablet hardware buttons include:

  • Power (with sliding lock)
  • Cltr-Alt-Del [sic]
  • Page up
  • Page down
  • Enter
  • Escape
  • Screen Rotation
  • Tablet shortcut menu

X61 Tablet: picture from here.

X200 Tablet: see below.

Linux Support

The hardware buttons (except power) are recognized by the standard atkbd kernel driver which emits the following scancodes:

Key X41 Scancode X60 Tablet Scancode X61 Tablet Scancode X200 Tablet Scancode X201 Tablet Scancode
Page up 0x6D NA NA NA NA
Page down 0x6E NA NA NA NA
Enter 0x69 0x69 0x69 NA NA
Esc 0x6B 0x6B 0x6b NA NA
Toolbox 0x68 0x68 0x68 0x66 0x68
Rotate 0x6C 0x6c 0x6c 0x6b 0x6c
(Unlabeled) 0x67 NA 0x67 0xe0 0x12 0x67
Padlock NA NA NA (nothing?) 0x66
Right NA 0x6D 0x6d NA NA
Left NA 0x6E 0x6e NA NA
Up NA 0x71 0x71 NA NA
Down NA 0x6F 0x6f NA NA

Notes:

  • X200 Tablet
    Layout: power (with sliding lock); clockwise-arrow (formerly unlabeled); rotate (two boxes and an arrow); Toolbox (the icon is now a menu); padlock.
    The padlock button seems to do nothing. It generates no scancode, and has no effect on the other buttons.
    The clockwise-arrow button returns a scancode pair. So you say $ setkeycodes e012 whatever.
  • X201 Tablet
    Layout: as X200 Tablet

The utility setkeycodes can be used to map these scancodes to keycodes. Read $ man setkeycodes for usage. For example, the following command will map the page up and page down buttons to their respective keys:

# setkeycodes 6e 109 6d 104

Models featuring this Device

Configuration with xbindkeys

The xbindkeys utility can be used to bind actions to the buttons once they have key codes (which they have by default in Debian). This example is for an X200 Tablet running Debian Wheezy, but should be applicable to other models and distributions.

First create a default ~/.xbindkeysrc file with this command:

$ xbindkeys --defaults > ~/.xbindkeysrc

This file will contain the key bindings for each key, and the commands associated with them. More information on the file can be found on ArchWiki's Xbindkeys page.

Next, use the $ xbindkeys -k command to generate the bindings to add to it. When the command is run, a window with a white background will appear. Select it and press the key you wish to bind. It will close and the binding will be printed to the terminal. For example (for the Tablet rotate button):

"(Scheme function)"
    m:0x0 + c:161
    NoSymbol

Copy and paste this into your ~/.xbindkeysrc file, replacing "(Scheme function)" with the command you wish to execute when the button is pressed.

A ~/.xbindkeysrc for an X200 Tablet might look like this:

# (Automatically generated documentation)
# ...

#Tablet Rotate button (run rotate script)
"~/scripts/rotate.sh"
# Replace the line above with the path to the script
    m:0x0 + c:161
    NoSymbol

#Tablet Toolbox button (show cellwriter)
"cellwriter --show-window"
    m:0x0 + c:149
    NoSymbol

This file binds the Tablet rotate button to a bash script that rotates the display (see below), and the Tablet shortcut button to the cellwriter input panel.

The bindings will only work while $ xbindkeys is running, however. Most desktop environments have a GUI to run commands at login. In Gnome 3, this is the Startup Applications app.

Screen rotation script

The example ~/.xbindkeysrc file above references a bash script that performs screen rotation. This is listed below:

#!/bin/bash
tablet="Serial Wacom Tablet stylus"

# Get the current orientation of the tablet
rotate=$(xsetwacom get "$tablet" Rotate)

# Work out the next tablet and screen orientations (rotating clockwise)
case "$rotate" in
    none) nextRotate="cw"
          nextOrient="right" ;;
    cw)   nextRotate="half"
          nextOrient="inverted" ;;
    half) nextRotate="ccw"
          nextOrient="left" ;;
    ccw)  nextRotate="none"
          nextOrient="normal" ;;
esac

# Rotate the screen
xrandr -o $nextOrient

# Rotate the tablet
xsetwacom set "$tablet" Rotate $nextRotate

Save this as a text file with the extension .sh somewhere on your system, mark it executable with $ chmod +x <path to script>, and put the path in your ~/.xbindkeysrc, on the appropriate line.

You may have to replace "Serial Wacom Tablet stylus" with the name of your Wacom tablet. You can find this with the $ xsetwacom list devices command.

See also