Dec. 31, 2019, 8:16 p.m.

Binding X200T physical tablet buttons with xbindkeys

Problem:

I am unable to find a program that will easily bind keys graphically when using i3wm.

Solution:

After browsing thinkwiki, I found the solution to this problem.

We will use xbindkeys and cellwriter, you can easily install it with apt.

$ sudo apt install cellwriter xbindkeys

Generate the default configuration of xbindkeys:

$ xbindkeys --defaults > ~/.xbindkeysrc

To determine what key code corresponds to our physical hardware buttons, we use this command:

$ xbindkeys -k

Output:

Press combination of keys or/and click under the window.
You can use one of the two lines after "NoCommand"
in $HOME/.xbindkeysrc to bind a key.

This command will print out the key code that we will then copy to the .xbindkeysrc file.

The following are my hardware key codes for my X200T:

Ctrl+Alt+Del button:

"(Scheme function)"
    m:0x0 + c:162
    XF86TaskPane

Rotate button:

"NoCommand"
    m:0x0 + c:161
    XF86RotateWindows

Toolbox button:

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

Other Misc Keyboard buttons:

ThinkVantage button:

"(Scheme function)"
    m:0x0 + c:156
    XF86Launch1

Volume Mute button:

"(Scheme function)"
    m:0x0 + c:121
    XF86AudioMute

Volume down button:

"(Scheme function)"
    m:0x0 + c:122
    XF86AudioLowerVolume

Volume up button:

"NoCommand"
    m:0x0 + c:123
    XF86AudioRaiseVolume

To bind command to these buttons using xbindkeys, we replace the (Scheme function) and No command with our program executable path or script path. and rrun xbindkeys in the background for it to work.

Screen Rotate binding:

Here is the bash script for rotating the screen and the stylus but before we continue, we need to determine our wacom device name by executing xsetwacom:

$ xsetwacom list devices
Wacom Serial Penabled 1FG Touchscreen Pen stylus    id: 12  type: STYLUS    
Wacom Serial Penabled 1FG Touchscreen Pen eraser    id: 13  type: ERASER

Save this file in the user home directory: rotate.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
tablet="Wacom Serial Penabled 1FG Touchscreen Pen 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

The content of the file: .xinitbindkeys

#Tablet Rotate button (run rotate script)

"~/rotate.sh"
    m:0x0 + c:161
    XF86RotateWindows

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

Now, run the command xbindkeys in the background then press your hardware button to rotate the screen.