LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   Mapping Multimedia Keyboard - Need more help (https://www.linuxquestions.org/questions/linux-hardware-18/mapping-multimedia-keyboard-need-more-help-260049/)

hazza 12-26-2004 09:54 PM

I found that I had to patch setkeycodes under MDK 10.1 to allow me to specify keycodes greater than 127. For my Logitech Access Keyboard I managed to map most of the multimedia keys so that I can use the xkb layout unmodified:

Code:

#!/bin/sh

# setkeycodes-logiak        Use setkeycodes to map the unmapped Logitech Access
#                        Keyboard multimedia keys to keycodes that allow the xkb
#                        layout to be used unmodified.
#
# Scancode        Keycode                Key
# e011                ?                Messenger
# e012                152                Webcam
#
# e03b                212                New
# e03c                137                Reply
# e03d                213                Forward
# e03e                214                Send
#
# e043                219                My Computer
# e044                220                My Documents
# e057                228                My Pictures
# e058                229                My Music

setkeycodes        e012 152 \
                e03b 212 \
                e03c 137 \
                e03d 213 \
                e03e 214 \
                e043 219 \
                e044 220 \
                e057 228 \
                e058 229

I used an exhaustive method to find kernel keycodes that match the keycodes seen by xkb. It involves running xev and a loop to cycle through the keycodes above 127, pressing the key I chose to map, and making a note a bit of paper when a keycode I recognised in xev came up. I ran the following shell script as root in an X terminal.

Code:

#!/bin/sh
#
# Usage: scankeycodes SCANCODE
#

SCANCODE=$1

let i=128
while [ $i -lt 240 ]; do
        echo "set scancode $SCANCODE to keycode $i"
        setkeycodes $SCANCODE $i || exit 1
        sleep 5
        let i=i+1
done

Quote:

Originally posted by TheVisionary
I am also trying to setup a media USB keyboard and found that some keys don't show anything.
Maybe this info can help:
http://www.tcnj.edu/~tolboom2/globlink_rf88.html

The USB keyboard driver doesn't appear to have any code in it that would print a message when a unmapped key is pressed. Try using "showkey -s" in a virtual console to find the scancode of keys that don't show up in xev. Then you can use setkeycodes as described above to map the unmapped keys to some keycodes.

Since there doesn't appear to be an xkb layout defined for your keyboard you could use the keycodes defined in include/input.h of the kernel source. For example, if you had a Mail multimedia key with a scancode of e06c, then you could use the keycode defined in input.h:

#define KEY_MAIL 155

You could then use a setkeycodes script of:

Code:

#!/bin/sh
#
# setkeycodes.sh
#

KEY_MAIL=155

setkeycodes e06c $KEY_MAIL

Then you can define an xkb layout as described in the previous posts.

maejrep 12-29-2004 03:19 AM

Ok, bare with me, ... this is going to be long and wordy, but I'm tired and it's just easier to put my train of thought down in words than to concentrate on making it short/comprehendable.

I just bought a Logitech COrdless Desktop LX 700 combo, and was trying to get it setup on gentoo (Gnome 2.8, gentoo-dev-sources 2.6.9 kernel). I spent a lot of time on this forum and many others trying to figure out all my problems, and bit by bit, I was able to figure some things out, while others still remain a mystery.

My old Dell Multimedia keyboard was having problems where it would not send any scancodes that were greater than a certain max (not sure where it cut off, but I would assume at 255, or even 127). The keys wouldn't even show up in `showkey -s`, which means the kernel was dropping it at a very early stage. So anyway, I had heard a lot of good things about Logitech in general for linux, so I decided to try it.

One thing I noticed is that it was reading scancodes, which was good, but no keycodes, and checking dmesg explained why (use setkeycodes). So I mapped the scancodes to available keycodes, and stuck that in my local.start -- now xev was able to pick up the keycodes (NOTE that the keycodes you feed to setkeycodes are NOT the same keycodes that xev/X detects!)

So, next I wanted to get all the buttons working on my mouse (10 buttons including scroll, 2 of which are the tilt wheel) Well, no matter what I did with xorg.conf, it wouldn't detect the 2 side buttons, the top "extra" button, or the tilt positions. I read that only evdev would allow more than 7 buttons, but before trying that, I wanted to see if connecting it via USB would help any, so I removed the USB-to-PS/2 adapter from the keyboard cord and unplugged the mouse cord, and tried it out.

At that point I could get all the mouse buttons to work (including tilt wheel, woohoo!), but then realized that my media keys stopped working again. I checked showkey -s and got nothing (well, certain keys do work, like Mute, Vol Up/Dn, E-mail, Play, Prev, Next, but none of the others), but showkey -k surprisingly did show keycodes for those keys (all > 255, ... not surprisingly) So basically, I was back at the same point with my old keyboard, not being able to use the extra keys because the keycodes were too high. It's kind of strange that the only difference was the USB/PS2 connection. With PS/2, the scancodes work properly and you can map them to a good keycode, which you can then map to a XF86 symbol, which can then be mapped to an action (whew), but with USB, you get no scancode, invalid keycode, and thus no way to use those keys.

So... I'm back at PS/2, my keyboard works (at least all the keys are usable - I haven't done anything useful with any of them other than the media keys, mainly because Gnome's new keyboard shortcut handler sucks), and I've managed to get 7 buttons working on the mouse (tilt L/R don't work, nor does the top extra button, but the scroll wheel and the two side buttons get a response from xev on unique Button numbers).

I know that's a lot of rambling (excuse me, it's 2am and I need sleep), but that might help someone out who runs into the same issues. If I had more time I would look through keyboard.c, hid-input.c, atkbd.c, etc, and just hack my way through it, but right now I don't feel like it.

So at the moment, the only part that is not working are those 3 "buttons" on the mouse. I think the tilt wheel is just because it's new and hasn't been fully supported in evdev yet (soon I hope), and I have no clue why button #8 doesn't work.

maejrep 12-29-2004 03:30 AM

By the way, it seems that some actions would work best as keystrokes, and others as commands, but I'm running into problems with Gnome... Gnome only lets you map a key to a preset action, and it doesn't let you customize it any further than that. For example... the "Media" key would usually be used to execute XMMS or something like that, but Gnome doesn't give you that option. SO what would be the most logical way to have that key execute xmms? And for the zoom in/out buttons, I know of the symbols XF86ZoomIn and ZoomOut, but once it's mapped to that, what can you actually do with it? I'd like them to adjust text size in applications that allow it (^+/^-). I really hate to have to use multiple programs to handle the keys like that, but it seems with Gnome's key binding, we really don't have much of a choice. :/

Oh, and does anyone know what the point of the "%" key is, next to zoom in and out?

Lightner 12-29-2004 09:05 AM

I've also bought the LX700 combo, and I'm starting to set up the multimedia keys.
Can you post your scancodes and keycodes?

btw, I can't get the mouse to work. If I connect the mouse, the keyboard won't respond, and if I then connect the keyboard, the mouse stops working.
Right now I have my mouse in Xfree assigned to /dev/psaux (or /dev/input/mice, works too). How did you assign the mouse?

maejrep 12-29-2004 07:31 PM

I guess I should have mentioned that I did fall back on using evdev for the mouse. Here is my mouse section of the xorg.conf file:
Code:

Section "InputDevice"
    Identifier  "Mouse1"
    Driver      "mouse"
    Option      "Protocol" "evdev"
    Option      "Dev Name" "ImExPS/2 Logitech Explorer Mouse"
    Option      "Dev Phys" "isa0060/serio1/input0"
    Option      "Device" "/dev/input/event1"
    Option      "Emulate3Buttons" "off"
    Option      "Buttons" "10"
    Option      "ZAxisMapping" "7 8 9 10"
    Option      "Resolution" "800"
EndSection

and .Xmodmap is:
Code:

pointer = 1 2 3 6 7 8 4 5 9 10

keycode 212 = XF86Eject
keycode 218 = XF86ZoomIn
keycode 120 = XF86ZoomOut
keycode 216 = XF86Away
keycode 213 = XF86Close
keycode 121 = XF86Messenger
keycode 229 = XF86Music
keycode 214 = XF86Documents
keycode 195 = XF86Pictures
keycode 223 = XF86ScreenSaver
keycode 215 = XF86WWW

I kept running into problems of assigning keys to already-used keycodes, so I had to reassign some of them a few times until I found something that worked. So basically here is what I added to my local.start (commands that get executed on boot, after everything else):
Code:

setkeycodes 6a 231
setkeycodes 6b 232
setkeycodes 6c 233
setkeycodes 6d 234
setkeycodes 6e 235
setkeycodes e001 238
setkeycodes e002 239
setkeycodes e003 214
setkeycodes e004 215
setkeycodes e011 216
setkeycodes e013 217
setkeycodes e014 218
setkeycodes e015 219
setkeycodes e025 220
setkeycodes e026 221
setkeycodes e02c 222
setkeycodes e02d 224
setkeycodes e02f 225
setkeycodes e031 213
setkeycodes e055 227
setkeycodes e074 228
setkeycodes e075 229
setkeycodes e078 230

I got those scancodes by pressing the keys and watching the dmesg output for the scancode, and the keycode is pretty much trial and error unless you know which kernel keycodes are free (since the xev keycode will vary greatly from what you enter here, for example: all the numbers above are more or less consecutive, but the xev scancodes vary from 120 to 220 or more.)

By the way, you mention one device working while the other isn't -- make sure you aren't using the USB connection and the PS/2 at the same time. It is designed to work either a) Mouse and Keyboard both connected via PS/2 (with the USB->PS/2 converter on the keyboard cable), or b) ONLY the keyboard connected via USB. Mine is currently working using the two PS/2 connectors.

hazza 12-29-2004 08:37 PM

If you are working on mapping the multimedia keys of a keyboard that doesn't already have an XKB layout in X then this script will help with finding keycodes to use with setkeycodes:

Code:

#!/bin/sh
#
# Get keycode symbols for keycodes above 127 from input.h.
#

INPUT_H=/usr/src/linux/include/linux/input.h

cat <<EOF
#!/bin/sh

#
# Keycodes extracted from $INPUT_H
#
EOF

sed -r '/^#define KEY_[^ \t]+[ \t]+[1-2][0-9]{2}/!d;/1[0-1][0-9]/d;/12[0-7]/d' $
INPUT_H \
 |sed 's/\(^#define \)\(KEY_[^ \t]*\)\([ \t]*\)\([0-9]*\)/\2=\4/'

cat <<EOF

#
# Keycodes below 127
#
KEY_MUTE=113
KEY_VOLUMEDOWN=114
KEY_VOLUMEUP=115
KEY_POWER=116
EOF

It will output key symbols defined in the kernel header input.h that have a keycode above 127. I added a few keycodes with a value below 128 manually. As has been noted above these keycodes are same as those in X. I'm interested to know if anyone has worked out a formula to convert between the two as I was unable to find one.

Lightner 12-31-2004 08:07 AM

I used getkeycodes (as root) to show a list of all the used keycodes. The output is somewhat difficult to read, but at least I didn't had an issue assinging the correct keycodes:)

This is a complete list of my keycodes, functions, scancodes and the issues setkeycodes:

Code:

keycode 36        = Enter
keycode 99          = Cancel                = 6d                setkeycodes 6d 101
keycode 139          = Switch frame                = e001                setkeycodes e001 120
keycode 121        = Down                        = e002                setkeycodes e002 122
keycode        122        = Up                        = e003                setkeycodes e003 123
keycode        133        = Zoom out                = e004                setkeycodes e004 129
keycode        134        = Zoom in                = 6a                setkeycodes 6a 130
keycode        135        = %                        = 6b                setkeycodes 6b 131
keycode        140        = Camera                = e014                setkeycodes e014 132
keycode 248        = Music                        = e013                setkeycodes e013 133
keycode        108        = Photos                = e015                setkeycodes e015 134
keycode        109        = My Documents                = e055                setkeycodes e055 135
keycode 144        = Previous
keycode 153        = Next
keycode        122        = Flame                        = e031                setkeycodes e031 136
keycode        188        = Rec                        = e078                setkeycodes e078 137
keycode 237        = Media
keycode 160        = Mute sound
keycode        245        = Remote control        = e02d                setkeycodes e02d 138
keycode 174        = Volume down
keycode 176        = Volume up
keycode        158        = Eject                        = e02f                setkeycodes e02f 139
keycode        110        = Audio Preset 1        = e02c                setkeycodes e02c 141
keycode        111        = Audio Preset 2        = e025                setkeycodes e025 144
keycode        112        = Audio Preset 3        = e026                setkeycodes e026 145
keycode 162        = Play/pauze
keycode 164        = Stop
keycode 236        = Email
keycode        113        = Messenger                = e011                setkeycodes e011 146
keycode        147        = Status                = e075                setkeycodes e075 147
keycode        159        = Webcam                = e074                setkeycodes e074 148
keycode 223        = Sleep
keycode 161        = Calculator

The keycodes that don't come with a setkeycodes already had a keycode assigned to them.

So far so good:)

After that, i made the following script, to be sure that they scancodes are always assinged to a keycode:

Code:

#!/bin/sh
setkeycodes 6a 130        # Zoom in        134
setkeycodes 6b 131        # %                135
setkeycodes 6d 101        # Cancel        99
setkeycodes e001 120        # Switch frame        139
setkeycodes e002 122        # Down                121
setkeycodes e003 123        # Up                122
setkeycodes e004 129        # Zoom out        133
setkeycodes e011 146        # Messenger        113
setkeycodes e013 133        # Music                248
setkeycodes e014 132        # Camera        140
setkeycodes e015 134        # Photos        108
setkeycodes e025 144        # Audio Preset2 111
setkeycodes e026 145        # Audio Preset3 112
setkeycodes e02c 141        # Audio Preset1 110
setkeycodes e02d 138        # Remote Ctrl  245
setkeycodes e02f 139        # Eject                158
setkeycodes e031 136        # Flame                122
setkeycodes e055 135        # My Documents  109
setkeycodes e074 148        # Webcam        159
setkeycodes e075 147        # Status        147
setkeycodes e078 137        # Rec                188

I saved this script as ./root/multimediakeys
Then I adjusted rcS.d and init.d so that it would automatically launch the /root/multimediakeys script.

Lightner 01-01-2005 09:16 AM

Just tested the mouse on a Win 2k machine. Doesn't work either.
Guess i simply bought the wrong box.. :cry:

I also found out that having a .xmodmap config file in your homedir doesn't work in Gnome, because gnome has its own keyboard shortcuts, and those overrule the xmodmap settings.
So now I am setting my machine up like this: http://foolish.fedorausers.org/gnome...uts/index.html

Works fine, though it takes more time to set it up..

hazza 01-01-2005 10:18 AM

Quote:

Originally posted by Lightner
I also found out that having a .xmodmap config file in your homedir doesn't work in Gnome, because gnome has its own keyboard shortcuts, and those overrule the xmodmap settings.
I had a workaround to load the xmodmap settings after the keyboard layout for KDE. I've looked into whether this could be done with GNOME but it doesn't look likely. It would require somehow stopping GNOME from loading a keyboard layout using XKB. That leaves the option of creating a new XKB layout and a patch for it so you can post it. It's possible now to have a somewhat generic XKB layout using the keycodes defined in the kernel header input.h if you have a 2.6.x version of it.

rpg 01-14-2005 01:37 PM

Followup on setkeycodes
 
A probably stupid question following up on Lightner's post.

When I try to use setkeycodes, I get an error:

Code:

setkeycodes e011 216
setkeycodes: code outside bounds

and the manpage says that the second argument keycode must be 0-127.

Am I doing something wrong? I'm using a 2.6.x kernel (Mandrake 10.0 Official).

Thanks!

Lightner 01-14-2005 01:40 PM

You might want to try to map a lower keycode to the scancode..?

rpg 01-14-2005 02:16 PM

I'm sorry --- I think I still don't understand well enough. It seems from other examples in this thread, that SOMETHING happens to the second argument to setkeycodes inside --- it seems like those numbers from 0-127 turn into some other numbers internally. Is there any way, short of reading the code, to figure out what that process is?

If I'm restricted to only 0-127, and those are just 0-127, don't I end up crushing the normal alphanumeric keys?

I'm sorry to be asking such dumb questions, but I haven't had much luck figuring out how the keyboard driver works from just the manpages.

Thanks!

hazza 01-14-2005 07:00 PM

Quote:

Originally posted by rpg
I'm sorry --- I think I still don't understand well enough. It seems from other examples in this thread, that SOMETHING happens to the second argument to setkeycodes inside --- it seems like those numbers from 0-127 turn into some other numbers internally. Is there any way, short of reading the code, to figure out what that process is?

If I'm restricted to only 0-127, and those are just 0-127, don't I end up crushing the normal alphanumeric keys?

I'm sorry to be asking such dumb questions, but I haven't had much luck figuring out how the keyboard driver works from just the manpages.

Thanks!

You need to patch setkeycodes as it restricts the keycodes to 0-127:

Code:

--- console-tools-0.2.3/kbdtools/setkeycodes.c.old        2005-01-15 11:20:34.257857000 +1030
+++ console-tools-0.2.3/kbdtools/setkeycodes.c        2005-01-15 11:24:59.020950609 +1030
@@ -75,7 +75,7 @@
          a.scancode -= 0xe000;
          a.scancode += 128;
        }
-      if (a.scancode > 255 || a.keycode > 127)
+      if (a.scancode > 255 || a.keycode > 239)
        badusage(_("code outside bounds"));
      if (ioctl(fd,KDSETKEYCODE,&a))
        {


lazyuser 01-21-2005 05:01 PM

Hello,

I haven't read all of this post, so if this is in the wrong direction excuse me. To use the multimedia functions on my keyboard I use a simple utlity called lineak http://lineak.sourceforge.net/ , what it does is its a daemon that waits for the multimedia function to be pressed. Hence when I press the play button xmms starts or pauses depending on the state. Forward for the next song, previous for the previous song. And its simple to set up. Also I checked using lineakd -l command and your keyboard is supported. Using this config paramter, lineakd -c LTCDP Logitech Cordless Desktop Pro, then you edit the .lineak file for what you want each command to do. Plus if you install the on display program, it comes up with a cool little text on your monitor depending on what your doing.

Lazyuser

hazza 03-31-2005 12:53 AM

I have been working on configuring the multimedia keys for an Acer Aspire 1691 WLMi notebook. My setkeycodes script so far is:

Code:

KEY_HELP[0]=e025                # mapping key changes scancode to e075
KEY_HELP[1]=138
#KEY_CONFIG[0]=e026            # mapping key changes scancode to e02b
#KEY_CONFIG[1]=202
KEY_BRIGHTNESSDOWN[0]=e06f      # mapping key changes scancode to e04c
KEY_BRIGHTNESSDOWN[1]=224
KEY_BRIGHTNESSUP[0]=e06e        # mapping key changes scancode to e054
KEY_BRIGHTNESSUP[1]=225
KEY_PROG1[0]=e073              # mapping key changes scancode to e01f
KEY_PROG1[1]=148
KEY_PROG2[0]=e074              # mapping key changes scancode to e017
KEY_PROG2[1]=149

setkeycodes ${KEY_HELP[@]} ${KEY_CONFIG[@]} ${KEY_BRIGHTNESSDOWN[@]} ${KEY_BRIGHTNESSUP[@]} ${KEY_PROG1[@]} ${KEY_PROG2[@]}

I haven't quite decided what keycode to map some of the oddly marked Fn keys. My XKB layout patch to suit is:

Code:

--- xkb/rules/xorg.lst.orig    2004-12-18 05:21:35.000000000 +1030
+++ xkb/rules/xorg.lst  2005-03-11 16:11:33.000000000 +1030
@@ -22,6 +22,7 @@
  abnt2                Brazilian ABNT2
  airkey      Acer AirKey V
  acpi        ACPI Standard
+  aspire1690  Acer Aspire 1690 Keyboard
  azonaRF2300  Azona RF2300 wireless Internet Keyboard
  scorpius    Advance Scorpius KI
  brother      Brother Internet Keyboard
--- xkb/rules/xorg.xml.orig    2004-12-18 05:21:35.000000000 +1030
+++ xkb/rules/xorg.xml  2005-03-11 16:22:18.000000000 +1030
@@ -201,6 +201,12 @@
    </model>
    <model>
      <configItem>
+        <name>aspire1690</name>
+        <description>Acer Aspire 1690 Keyboard</description>
+      </configItem>
+    </model>
+    <model>
+      <configItem>
        <name>azonaRF2300</name>
        <description>Azona RF2300 wireless Internet Keyboard</description>
      </configItem>
--- xkb/rules/xorg.orig 2004-12-18 05:21:35.000000000 +1030
+++ xkb/rules/xorg      2005-03-11 16:10:32.000000000 +1030
@@ -98,6 +98,7 @@
  *            =      +pc/%l[4]%(v[4]):4

 ! $inetkbds = airkey acpi scorpius azonaRF2300 \
+              aspire1690 \
              brother \
              btc5113rf btc5126t btc9000 btc9000a btc9001ah btc5090\
              cherryblue cherrybluea cherryblueb \
--- xkb/symbols/inet.orig      2004-12-18 05:21:33.000000000 +1030
+++ xkb/symbols/inet    2005-03-26 19:29:42.000000000 +1030
@@ -38,6 +38,28 @@
    key <I5E>  {      [ XF86PowerOff          ]      };
 };

+partial alphanumeric_keys
+xkb_symbols "aspire1690" {
+    name[Group1]= "Acer Aspire 1690 Keyboard";
+
+    key <I75>  {      [ Help                  ]      };
+    key <I01>  {      [ XF86Launch3          ]      };
+
+    key <I1F>  {      [ XF86Launch1          ]      };
+    key <I17>  {      [ XF86Launch2          ]      };
+    key <I32>  {      [ XF86WWW              ]      };
+    key <I6C>  {      [ XF86Mail              ]      };
+
+    key <I20>  {      [ XF86AudioMute        ]      };
+    key <I2E>  {      [ XF86AudioLowerVolume  ]      };
+    key <I30>  {      [ XF86AudioRaiseVolume  ]      };
+
+    key <I22>  {      [ XF86AudioPlay, XF86AudioPause ] };
+    key <I24>  {      [ XF86AudioStop        ]      };
+    key <I10>  {      [ XF86AudioPrev        ]      };
+    key <I19>  {      [ XF86AudioNext        ]      };
+};
+
 // Azona

 partial alphanumeric_keys
--- xkb/symbols.dir.orig        2004-12-18 05:21:32.000000000 +1030
+++ xkb/symbols.dir    2005-03-11 16:09:16.000000000 +1030
@@ -484,6 +484,7 @@
 --p----- a------- czsk(def_sk_us_prog)
 --p----- a------- czsk(def_cz_us_prog)
 --p----- a------- inet(airkey)
+--p----- a------- inet(aspire1690)
 --p----- a------- inet(azonaRF2300)
 --p----- a------- inet(acpi)
 --p----- a------- inet(scorpius)

As usual I've noticed the rather odd behaviour where mapping a key to a keycode changes its scancode. If anyone has some inside knowledge into predicting this change in scancode it would be handy to know.


All times are GMT -5. The time now is 06:09 PM.