This is what I want:
- I press Scroll Lock on my keyboard.
- The Scroll Lock LED on my keyboard lights up.
- The keys around the right-hand home row now controls the mouse pointer (moving it, clicking, right-clicking, dragging, etc. Like Mouse Keys on a regular keypad.)
- The rest of the keys either do nothing, the same as before or whatever.
- I press Scroll Lock again.
- The Scroll Lock LED turns off.
- No mouse keys.
It needs to work on Trisquel.
I've used xkb before to remap some keys, so I thought that perhaps xkb can do this. And it looks like it can:
However, I'm new to both Linux and xkb. I've managed to make very simple key remappings with xkb, but unfortunately I cannot figure out how to put all the above together, and in what files to put it. Solutions not involving xkb are OK too, as are partial solutions.
Answer
Before, I simply tried assigning the Pointer_Left
keysym to some key, and Pointer_EnableKeys
to scroll lock. However, that did not move the mouse pointer to the left. Instead, it did nothing at all.
Turns out that simply assigning a keysym to a key is not enough. The keysym needs to be interpreted as well. That is done in a "compat" file. On my system, they are located in /usr/share/X11/xkb/compat.
I’ve made my own keyboard layout, by following this excellent guide: http://hack.org/mc/writings/xkb.html. That means that I have a "teck.xkb" file (I call my layout "teck"). That file contains the following line:
xkb_compat { include "complete" };
Looking at /usr/share/X11/xkb/compat/complete reveals that that file includes a file called "mousekeys" in the same folder. Bingo.
The mousekeys file contains interpretations for keysyms to control the mouse. It contains the required interpretation of Pointer_EnableKeys
that is mentioned in one of the link in my question. However, it does not contain interpretations for Pointer_Left
(and Pointer_Right
and so on). That’s why it didn’t work for me before. Instead, lots of KP_*
keysyms are interpreted. After all, the standard is to put mouse keys on the keypad.
Luckily, at the end of the mousekeys file is some code for setting up an indicator for mouse keys. Perfect!
So I copied the mousekeys file into a new folder called "compat" next to my teck.xkb file, and renamed it to "teck_mousekeys". I updated my teck.xkb file accordingly:
xkb_compat { include "teck_mousekeys+complete" };
Then I started editing the teck_mousekeys file. Instead of using KP_*
keysyms, I used the ones I wanted (the keys around the right-hand home row). Here is the result:
default partial xkb_compatibility "mousekeys" {
interpret.repeat= True;
interpret m {
action = MovePtr(x=-1,y=+1);
};
interpret comma {
action = MovePtr(x=+0,y=+1);
};
interpret period {
action = MovePtr(x=+1,y=+1);
};
interpret j {
action = MovePtr(x=-1,y=+0);
};
interpret l {
action = MovePtr(x=+1,y=+0);
};
interpret u {
action = MovePtr(x=-1,y=-1);
};
interpret i {
action = MovePtr(x=+0,y=-1);
};
interpret o {
action = MovePtr(x=+1,y=-1);
};
interpret k {
action = PointerButton(button=default);
};
interpret semicolon {
action = PointerButton(button=3);
};
interpret space {
action = PointerButton(button=default,count=2);
};
interpret y {
action = SetPtrDflt(affect=defaultButton,button=3);
};
interpret h {
action = SetPtrDflt(affect=defaultButton,button=2);
};
interpret n {
action = SetPtrDflt(affect=defaultButton,button=1);
};
interpret p {
action = LockPointerButton(button=default,affect=lock);
};
interpret apostrophe {
action = LockPointerButton(button=default,affect=unlock);
};
indicator "Scroll Lock" {
indicatorDrivesKeyboard;
controls= MouseKeys;
};
};
(The above assumes a QWERTY layout.)
In my custom keyboard layout I define scroll lock to toggle mouse keys:
key {[Pointer_EnableKeys]};
No comments:
Post a Comment