add a second keyboard with a different mapping

Timothy S. Nelson wayland at wayland.id.au
Tue Jul 21 00:31:17 PDT 2009


On Tue, 21 Jul 2009, Peter Hutterer wrote:

> On Mon, Jul 20, 2009 at 02:32:35PM +0000, Lennart Aangeenbrug wrote:
>> Hi all,How can i add a second USB keyboard, and map this
>> keyboard differently? The main keyboard is connected to PS/2, works fine
>> etc. The second one is working out of the box. I want to use the second
>> keyboard for Gimp and re-map some keys (like Q should be CTRL-SHIFT-N). So
>> my question is : how can i re-map the keys on the second keyboard? I think i
>> should add the keyboard to xorg, but i can't figure it out.
>>
>> The Xorg.conf (i'm working under Ubuntu 8.04) shows only
>>
>> Section "InputDevice"
>>     # generated from default
>>     Identifier     "Keyboard0"
>>     Driver         "kbd"
>> EndSection
>
> if you need two separate keyboards, you shouldn't use the kbd driver. Use
> evdev instead (there are be plenty of links on google to explain how to use
> evdev). use a device file of /dev/input/by-id/<keyboard name>-event and
> assign it the desired Option "XkbLayout", etc. in the config.
> It is also possible to set up two keyboards, one with the kbd driver and one
> with evdev (grabs must be enabled in evdev, evdev 2.1 and later requires
> Option "GrabDevice" "on").
>
> Note that depending on your desktop enviroment, the layout set in the config
> may get overwritten so you may need to apply the layout at runtime anyway.
> This can be done with "setxkbmap -device <deviceid> -layout <whatever>" etc.

 	I'm running something a little like what you are wanting, so I thought 
maybe I should document my experience so that you could see what I get.  I did 
most of this setup a month or two ago, so some details may be vague.  I'm also 
mentioning a few problems along the way in hopes that someone (Peter? :) ) 
might be able to suggest something.

 	The first thing was to get the multiple keyboards working.  I have it 
configured to use the "kbd" driver, but looking at the startup log, it seems 
to be ignoring what I told it and using evdev anyway, which is fine by me.

 	The next thing was to test running the keyboards with different maps. 
Now that configuration I'm after is like this:

Keyboard 1: Standard us+pc105+inet setup
Keyboard 2: 4 layouts; us-intl, el (Greek), il (Hebrew), and a custom layout
 	that lets me type various mathematical symbols

 	So, the configuration of keyboard 1 is automatically the way I want 
it, so I don't have to do anything to it except ensure that I don't mess it 
up.  For keyboard 2, I have a script that gets run when I log in to XWindows 
that runs this command:

setxkbmap -device <deviceid> '<layouts>'

 	A real-life example might look something like this:

setxkbmap -device 3 'us,el,il,custom' -option 'grp:switch,grp:scroll_toggle,grp_led:scroll,lv3:ralt_switch'

 	...or something like that (and all on one line).  Please note that the 
use of scroll lock and the scroll led were things that I had to put in to the 
keyboard configuration in /usr/share/X11/xkb/ (this is a Fedora box).  Note 
also that the device ID can be gotten by running the command "xinput list". 
My script that runs on login parses the output of "xinput list" to get the 
appropriate device ID, since it's different different times.

 	Unfortunately, my USB keyboard drops out every once in a while, and, 
while it comes back online immediately, it has unfortunately lost its 
configuration, and the setxkbmap script needs to be run manually at that 
point.  I'd like to be able to have the new USB keyboard trigger the script, 
but that doesn't seem to be what happens.

 	Another problem is that, if I have Keyboard 2 set to Greek (layout 2), 
if I type on keyboard 1, then Keyboard 2 switches back to layout 1.  If I 
recall correctly, Peter implied that either:
1.	It's been fixed in a newer version than what I'm using
2.	He fixed it when I described the problem, or
3.	He hoped he'd have time to fix it sometime

 	Unfortunately, I've forgotten which of these it was.

 	Hopefully this has helped in some way.  The only thing I haven't 
answered is how to remap keys.  I'm afraid I don't know the answer; I know how 
to remap single keys to single keys, but not a single key to multiple keys. 
The reason I don't know is because I have an Avant Stellar, and my keyboard 
will remap any key I want to any other key (except Right Ctrl), before it 
sends it down the keyboard cable.  But I realise that not everyone wants to 
buy an Avant Stellar.

 	I'm also hoping that someone will build some cool keyboard macroing 
into the Linux kernel (ie. one keystroke to multiple keystrokes).  But it 
probably won't happen.

 	HTH some.

 	:)


---------------------------------------------------------------------
| Name: Tim Nelson                 | Because the Creator is,        |
| E-mail: wayland at wayland.id.au    | I am                           |
---------------------------------------------------------------------

----BEGIN GEEK CODE BLOCK----
Version 3.12
GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- 
PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y-
-----END GEEK CODE BLOCK-----




More information about the xorg mailing list