You are not logged in.

#1 2010-01-06 11:04:51

onguarde
Member
Registered: 2008-09-14
Posts: 144

Xmodmap - Disable Shift Modifier on Keyboard Key

Peace all!

I changed my right shift key to function as a Backspace key.
All's well except the Shift modifier which refuses to go away!

$ xmodmap
xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  BackSpace (0x3e)
lock        Mode_switch (0x42)
control     Control_L (0x25),  Delete (0x69)
mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

The setup is mostly from http://www.in-ulm.de/~mascheck/X11/xmodmap.html
Basically, it removes all the modifiers and reapply it later after we've finished swapping keys.

Here's my .Xmodmap,

!! As a requirement, we need to clear applied modifier before we can map any key to a different keysym. Else the new key will still have the old modifier applied as well as the new one.
clear Shift
clear Lock
clear Control
clear Mod1
!clear Mod2
clear Mod3
!clear Mod4
!clear Mod5

! Tab
keycode 23 = Tab ISO_Left_Tab Return

! RShift
keycode 62 = BackSpace

! Caps_Lock
keycode 66 = Mode_switch

! RAlt
! keycode 108 = Alt_R

! LAlt
!keycode 64 = Control_L            ! Depreacated in favour of simply alt tab key combi
!keycode 64 = Alt_L Alt_L BackSpace

! RCtrl
keycode 105 = Delete

! Page Down
!keycode 117 = Delete            ! Different keyboard - Menu key(useful) instead

keycode 25 = w W Up
keycode 38 = a A Left
keycode 39 = s S Down
keycode 40 = d D Right

keycode 31 = i I Up
keycode 44 = j J Left
keycode 45 = k K Down
keycode 46 = l L Right

keycode 30 = u U Page_Up
keycode 32 = o O Page_Down

keycode 43 = h H Home
keycode 47 = semicolon colon End

!! The modifiers are added based on their keysym name(not their keycode). Mod1 to 5 are abritary(A general modifier is added to keys like Alt)
   add shift   = Shift_L
!   add lock    = Caps_Lock
   add control = Control_L
   add mod1    = Alt_L
!   add mod2    = Mode_switch
   add mod3    = Mode_switch
!   add mod4    = Meta_L Meta_R
!   add mod5    = Num_Lock

Thanks in advance!

Last edited by onguarde (2010-01-06 11:14:09)

Offline

#2 2010-01-09 02:46:30

onguarde
Member
Registered: 2008-09-14
Posts: 144

Re: Xmodmap - Disable Shift Modifier on Keyboard Key

Anyone has any ideas? Maybe I didn't express myself clear enough.

Basically, I mapped my right shift key to function as backspace. The key now produces not only a "Backspace" but also shift as well. So when I press it quickly to delete a character, at times, the next character I input is capitalised.

I managed to narrow the problem to the "clear Shift" modifier line in xmodmap. It doesn't seem to be working even though I commented the rest of the relevant parts(eg. add shift).

I still get,

$ xmodmap
xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):
shift       Shift_L (0x32),  Shift_R (0x3e)

The shift modifier is still there even though I cleared it!

Totally stumped...

Last edited by onguarde (2010-01-09 02:48:00)

Offline

#3 2010-01-09 04:27:35

chpln
Member
From: Australia
Registered: 2009-09-17
Posts: 361

Re: Xmodmap - Disable Shift Modifier on Keyboard Key

Shift_R is removed from the shift modifier map and behaves correctly here.  Just to be sure, are there any errors when running 'xmodmap /path/to/.Xmodmap'?

Could you see if:

xmodmap -e 'clear shift'
xmodmap -e 'keycode 62 = BackSpace'
xmodmap -e 'add shift = Shift_L'

has the desired effect?

Last edited by chpln (2010-01-09 04:29:04)

Offline

#4 2010-01-09 05:04:53

onguarde
Member
Registered: 2008-09-14
Posts: 144

Re: Xmodmap - Disable Shift Modifier on Keyboard Key

Hmm..  actually there is. But I tend to ignore it since everything else works fine.

X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  118 (X_SetModifierMapping)
  Value in failed request:  0x17
  Serial number of failed request:  26
  Current serial number in output stream:  26

I have no idea how to decipher this. Anyone knows?

Digging deeper, I found out that the offending line is,

add mod2    = Mode_switch

which is there to enable the mode_switch modifier mapped to my caps lock key.

! Caps_Lock
keycode 66 = Mode_switch

However, upon removing it, my mode_switch still works fine!
I think some clear/remove settings left over from the days of swapping alt/ctrl screwed it up.

Thanks for pointing me in the right direction!

Btw, is there a way to reset xmodmap settings to the default settings without restarting?

Here's my full .xmodmap if anyone cares. Main features are,
1) Mapped Rshift to Backspace
You'll be surprised how much hand movement you save by this alone.

2) Custom modifier(mode_switch) bound to capslock
Have access to arrow keys in the home row(globally in all apps)
Also added home/end and page up/down functions near home row for completeness.

All these allow for almost complete home/row typing in all applications when coupled with thinkpad's trackpoint and mouse buttons of course.

I'm curious about other implementations. What do you guys use?

!! As a requirement, we need to clear applied modifier before we can map any key to a different keysym. Else the new key will still have the old modifier applied as well as the new one.
clear Shift
clear Lock
clear Control
!clear Mod1
!clear Mod2
!clear Mod3
!clear Mod4
!clear Mod5

! Tab
keycode 23 = Tab ISO_Left_Tab Return

! RShift    ! Can't add (Shift+Backspace = Delete) - Breaks back function   
keycode 62 = BackSpace

! Caps_Lock
keycode 66 = Mode_switch

! RCtrl
keycode 105 = Delete

! LBack
keycode 166 = Alt_L

! Home Arrow Keys
keycode 31 = i I Up
keycode 44 = j J Left
keycode 45 = k K Down
keycode 46 = l L Right

keycode 30 = u U Page_Up
keycode 32 = o O Page_Down

keycode 43 = h H Home
keycode 47 = semicolon colon End

!! The modifiers are added based on their keysym name(not their keycode). Mod1 to 5 are abritary(A general modifier is added to keys like Alt)
   add shift   = Shift_L
!   add lock    = Caps_Lock
   add control = Control_L
!   add mod1    = Alt_L
!   add mod2    = Mode_switch
!    add mod2    = Mode_switch
!   add mod4    = Meta_L Meta_R
!   add mod5    = Num_Lock

Thanks again for all the help!

Last edited by onguarde (2010-01-09 05:18:15)

Offline

#5 2010-01-09 05:17:58

chpln
Member
From: Australia
Registered: 2009-09-17
Posts: 361

Re: Xmodmap - Disable Shift Modifier on Keyboard Key

onguarde wrote:

I have no idea how to decipher this. Anyone knows?

I've never been able to figure out the cause from the output.  Though, if xmodmap is throwing an error, your keymap is unlikely to behave properly.

onguarde wrote:

btw, is there a way to reset xmodmap settings to the default settings without restarting?

You're after 'setxkbmap'.

onguarde wrote:

I'm curious about other implementations. What do you guys use?

I've become accustomed to the hhkb-style layout.  Namely, making Caps_Lock a control key and swapping backslash / bar with BackSpace.  I also put Alt_R on a separate modifier map which I use for xmonad, multimedia controls, etc.  And the key to the right of right alt becomes the multi_key.  xmodmap settings are below.

keycode 51 = BackSpace
keycode 22 = backslash bar

keycode 135 = Multi_key

! SDL, for one, does not reference the modifier map.  Therefore we give
! Caps_Lock a control keysym.
keycode 66 = Control_L

clear lock
add control = Control_L

! xterm, urxvt seem to behave strangely (blocks input or ignores alt modifier)
! without Alt_R.  So swap Alt_R with an used keycode.  Here Hyper_L represents
! the right alt key.
remove mod1 = Alt_R
remove mod4 = Hyper_L
keycode 112 = Multi_key
keycode 108 = Hyper_L
keycode 207 = Alt_R
add mod1 = Alt_R
add mod4 = Hyper_L

Last edited by chpln (2010-01-09 05:25:40)

Offline

Board footer

Powered by FluxBB