LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Problem re-mapping non-standard keys to modifier keys (http://www.linuxquestions.org/questions/linux-general-1/problem-re-mapping-non-standard-keys-to-modifier-keys-873624/)

tias42 04-07-2011 01:06 PM

Problem re-mapping non-standard keys to modifier keys
 
I'm running Debian (Squeeze) and I have a toshiba portege m700. It has five buttons on the front just under the screen, which are the only ones accessible when you flip the screen over into tablet mode. One of them is for rotating the screen, and another is for switching to external display. I want to remap the remaining three to control, alt and super so that I can use shortcuts with the stylus.

The problem is, when I used showkey to find out the key codes, I found out that each button generates more than one key code:

Button 1:
key 126 press >> super_r, although this is distinct from the actual super key (125)
key 7 press >> 6
key 7 release
key 126 release

Button 2: (you can guess what this button was supposed to be for)
key 29 press >> control_L
key 56 press >> alt_L
key 111 press >> delete
key 111 release
key 56 release
key 29 release

Button 3:
key 125 press >> super_r, the same as keyboard super
key 45 press >> x
key 45 release
key 125 release

As far as I can tell both the key codes and scan codes for most of these are identical to the keys whose outputs they match. I don't know a way to remap all of these to a single keypress, and needless to say I don't want to lose keys like 6 or x. I've tried simply making the key combination a shortcut for what I want, but as I want modifier keys, the extra keypresses making up the shortcut interfere. Possibly it would help to write some sort of script to ignore the rest of the key events - after which I could just remap the first one to what I want, but I lack the expertise to do something like that myself.

Any help would be greatly appreciated. I've spent a fruitless day trawling the world wide interwebs to no avail, and it would be really good to get it working.

tredegar 04-08-2011 09:50 AM

Is the coding for the keys any clearer if you use xev to grab the codes?
I could not get showkey to work, and this is from man showkey
Code:

2.6 KERNELS
      In 2.6 kernels key codes lie in the range 1-255, instead of 1-127.  Key codes larger than 127 are returned as three bytes
      of  which  the  low  order  7  bits are: zero, bits 13-7, and bits 6-0 of the key code.  The high order bits are: 0/1 for
      make/break, 1, 1.

      In 2.6 kernels raw mode, or scancode mode, is not very raw at all.  Scan codes are first translated  to  key  codes,  and
      when  scancodes  are  desired,  the  key codes are translated back. Various transformations are involved, and there is no
      guarantee at all that the final result corresponds to what the keyboard hardware did send. So, if you want  to  know  the
      scan  codes sent by various keys it is better to boot a 2.4 kernel. Since 2.6.9 there also is the boot option atkbd.soft‐
      raw=0 that tells the 2.6 kernel to return the actual scan codes.


tias42 04-09-2011 12:41 AM

I tried it with xev, with results along a similar line. Here's what I got:

Code:


Button 1

KeyPress event, serial 32, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1044571, (703,-16), root:(709,466),
    state 0x0, keycode 134 (keysym 0xffec, Super_R), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyPress event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1044572, (703,-16), root:(709,466),
    state 0x40, keycode 15 (keysym 0x36, 6), same_screen YES,
    XLookupString gives 1 bytes: (36) "6"
    XmbLookupString gives 1 bytes: (36) "6"
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1044730, (703,-16), root:(709,466),
    state 0x40, keycode 15 (keysym 0x36, 6), same_screen YES,
    XLookupString gives 1 bytes: (36) "6"
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1044733, (703,-16), root:(709,466),
    state 0x40, keycode 134 (keysym 0xffec, Super_R), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

Button 2

KeyPress event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1060093, (703,-16), root:(709,466),
    state 0x0, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyPress event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1060095, (703,-16), root:(709,466),
    state 0x4, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyPress event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1060099, (703,-16), root:(709,466),
    state 0xc, keycode 119 (keysym 0xffff, Delete), same_screen YES,
    XLookupString gives 1 bytes: (7f) ""
    XmbLookupString gives 1 bytes: (7f) ""
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1060255, (703,-16), root:(709,466),
    state 0xc, keycode 119 (keysym 0xffff, Delete), same_screen YES,
    XLookupString gives 1 bytes: (7f) ""
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1060257, (703,-16), root:(709,466),
    state 0xc, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1060261, (703,-16), root:(709,466),
    state 0x4, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

Button 3

KeyPress event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1069481, (703,-16), root:(709,466),
    state 0x0, keycode 133 (keysym 0xffeb, Super_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyPress event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1069482, (703,-16), root:(709,466),
    state 0x40, keycode 53 (keysym 0x78, x), same_screen YES,
    XLookupString gives 1 bytes: (78) "x"
    XmbLookupString gives 1 bytes: (78) "x"
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1069486, (703,-16), root:(709,466),
    state 0x40, keycode 53 (keysym 0x78, x), same_screen YES,
    XLookupString gives 1 bytes: (78) "x"
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1069493, (703,-16), root:(709,466),
    state 0x40, keycode 133 (keysym 0xffeb, Super_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False


And for reference:


super key

KeyPress event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1074698, (703,-16), root:(709,466),
    state 0x0, keycode 133 (keysym 0xffeb, Super_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1074760, (703,-16), root:(709,466),
    state 0x40, keycode 133 (keysym 0xffeb, Super_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

6 key

KeyPress event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1053566, (703,-16), root:(709,466),
    state 0x0, keycode 15 (keysym 0x36, 6), same_screen YES,
    XLookupString gives 1 bytes: (36) "6"
    XmbLookupString gives 1 bytes: (36) "6"
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1053647, (703,-16), root:(709,466),
    state 0x0, keycode 15 (keysym 0x36, 6), same_screen YES,
    XLookupString gives 1 bytes: (36) "6"
    XFilterEvent returns: False

alt key

KeyPress event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1064655, (703,-16), root:(709,466),
    state 0x0, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1064715, (703,-16), root:(709,466),
    state 0x8, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

delete key

KeyPress event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1065572, (703,-16), root:(709,466),
    state 0x0, keycode 119 (keysym 0xffff, Delete), same_screen YES,
    XLookupString gives 1 bytes: (7f) ""
    XmbLookupString gives 1 bytes: (7f) ""
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1065673, (703,-16), root:(709,466),
    state 0x0, keycode 119 (keysym 0xffff, Delete), same_screen YES,
    XLookupString gives 1 bytes: (7f) ""
    XFilterEvent returns: False

control key

KeyPress event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1064072, (703,-16), root:(709,466),
    state 0x0, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1064153, (703,-16), root:(709,466),
    state 0x4, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

x key

KeyPress event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1072429, (703,-16), root:(709,466),
    state 0x0, keycode 53 (keysym 0x78, x), same_screen YES,
    XLookupString gives 1 bytes: (78) "x"
    XmbLookupString gives 1 bytes: (78) "x"
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6a00001,
    root 0x112, subw 0x0, time 1072511, (703,-16), root:(709,466),
    state 0x0, keycode 53 (keysym 0x78, x), same_screen YES,
    XLookupString gives 1 bytes: (78) "x"
    XFilterEvent returns: False


I just noticed that button 1 is right super, not left super, but it's still the only one with a unique ID. And my main problem is still that they are generating more than one key press.

tredegar 04-09-2011 01:49 AM

xev is reporting the same behaviour. Those are strange keys.
Does this change if you add the option atkbd.soft‐raw=0 to your kernel boot line?

tias42 04-09-2011 05:03 AM

No, it's the same. I'm pretty sure it's just lazy design of the laptop, rather than weird settings.


All times are GMT -5. The time now is 11:33 AM.