Cherry Linux keyboard and Java

Submitted by gunnar on Tue, 05/13/2008 - 19:04

Since I couldn't get the KeyMan utility that came with my Cherry keyboard to work with SuSE 10.3 I had problems getting the Cut, Copy and Paste keys to work. I tried using the KDE KHotKey service instead, and by defining input actions that map these keys to Ctrl+X, Ctrl+C and Ctrl+V I could use them in most applications.

Starting with Java 1.6 though, this isn't enough. Seems like Java can't handle mappings made for KHotKeys. To get the keys to work with Java applications I had to do two things:

  1. Remap the Cut, Copy and Paste keys using xmodmap to make them send key codes that are recognized by Java as VK_COPY etc.
  2. Change my KHotKey mappings to map these new key codes to Ctrl+C etc, with conditions to ensure that no mapping is made when the keys are used in a Java application.

The shell script for the first step is as follows:


# Map Copy to Java VK_COPY
xmodmap -e "keycode 248 = 0xFFCD"

# Map Cut to Java VK_CUT
xmodmap -e "keycode 188 = 0xFFD1"

# Map Paste to Java VK_PASTE
xmodmap -e "keycode 192 = 0xFFCF"

I run this script after KDE has started by placing a link in Autostart. Just linking to the script doesn't work because it is then run too early, before KDE has applied keyboard layout mappings. The following command delays the execution a bit:

sleep 3 && sh '/home/gugrim/scripts/cherry-xmodmap'

The second step is done in Personal Settings (Configure Desktop) / Regional & Accessibility / Input Actions. I added three Input Actions of type Generic with the following properties:


        F20, F16 and F18 for Cut, Copy and Paste respectively.


        Keyboard Input: Ctrl+X, Ctrl+C, Ctrl+V respectively.


            Active Window
                Simple Window: Matches Regular Expression: sun-awt-X11-.*

More conditional actions might be needed for some applications but these seem to be sufficient for most.