14

I have a macbook pro running Ubuntu 13.10 with FluxBox. Unfortunately, the power button is physically above the backspace where I would expect the delete key to be in. In OS X, the PowerKey program can be used to remap the power key to delete. How can I do something similar in X Windows?

I disabled the power key by editing /etc/systemd/logind.conf and setting HandlePowerKey = ignore After this, I can press the power button without shutting the laptop down.

Running xev -event keyboard reveals that the KeyPress for the power key is normally being eaten by another process:

MappingNotify event, serial 36, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

KeymapNotify event, serial 36, synthetic NO, window 0x0,
    keys:  1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

KeymapNotify event, serial 37, synthetic NO, window 0x0,
    keys:  1   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   

However by running only xterm directly from console, I was able to successfully get the keycode and remap the key.

xinit /usr/bin/xterm -- :1
xev -event keyboard | tee /tmp/junk.txt
tail -n ???? /tmp/junk.txt
MappingNotify event, serial 28, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

KeyPress event, serial 28, synthetic NO, window 0x600001,
    root 0xa1, subw 0x0, time 720369, (146,89), root:(148,91),
    state 0x0, keycode 124 (keysym 0x1008ff2a, XF86PowerOff), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x600001,
    root 0xa1, subw 0x0, time 720369, (146,89), root:(148,91),
    state 0x0, keycode 124 (keysym 0x1008ff2a, XF86PowerOff), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

MappingNotify event, serial 29, synthetic NO, window 0x0,
    request MappingKeyboard, first_keycode 8, count 248

At this point, it was also possible to map the key using xmodmap. I mapped it to backslash which is easier to see than delete:

 xmodmap -e "keycode 124 = backslash bar"

I could get a barely functional equivalent to run by adding this to ~/.fluxbox/keys but this is both ugly and slow enough to be unusable.

  # Remap the power off to a delete key...
  XF86PowerOff :Exec xdotool key Delete

How can I use xmodmap or setxkbmap to use the power button at the same time as a normal window manager?

3

I don't exactly understand the final sentence, question, but I can relate to the title of the question: "Remapping power key to delete".

Try replacing any "XF86PowerOff" or just the one corresponding to your keyboard with "Delete" in /usr/share/X11/xkb/symbols/inet.

You need to repeat this after a system update which updates that file.

1

It isn't an exact answer, but have you tried pressing fn+delete? This should act as a real Delete, vs its actual action of 'backspace' and is very near to the power key.

Another tip:

fn+enter acts as an Insert button, so you should be able to press shift+fn+enter and Paste like a middle click.

0

Its hard to say for sure. These may be things you've tried already, but they may lead to an easy solution.

Is xmodmap working for other keys, or is there something that fluxbox is doing which is breaking xmodmap entirely?

What happens if you start x, modmap the power key, and then start fluxbox? Does the mapping stick?

If running xmodmap before fluxbox works and keeps your settings, you can either write a shell script to call both in the proper order, or if you're using gdm it should read ~/.xmodmap or ~/.xmodmaprc automatically for you before fluxbox enters the picture.

  • Yes, xmodmap works. Right now, I have the right alt and right command remapped to delete and insert respectively using xmodmap -e "remove mod1 = Alt_L" -e "remove mod4 = Super_L" -e "add mod1 = Super_L" -e "add mod4 = Alt_L" -e "remove mod1 = Alt_R" -e "remove mod4 = Super_R" -e "keysym Alt_R = Delete" -e "keysym Super_R = Insert" – nathan Jan 31 '14 at 5:10
  • Can you include the output of xmodmap -pke within fluxbox? – Mike Fairhurst Jan 31 '14 at 22:54
  • @nathan so this is the problem of when xmodmap is run, after fluxbox or before. Had the same problem with awesome wm – Darek Feb 17 '15 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.