How to bind Ctrl+arrows to Home and End keys? xmodmap does not work

9,514

Solution 1

AutoKey can do bindings like this, but it requires running a service in the background (like ahk, but unlike xmodmap).

Configure a "phrase" where the text is <home>, the paste method is Keyboard, and the hotkey is <ctrl>-<left>:

AutoKey GUI

Solution 2

I'm using Apple aluminum keyboard on Ubuntu workstation and the following xmodmap commands did it for me:

# remap Ctrl_L to ModeSwitch, then use it to map arrow keys so that
# they act like on the MacBook keyboard with Fn key pressed 
xmodmap -e "keycode 37=Mode_switch"
xmodmap -e "keycode 113 = Left NoSymbol Home"
xmodmap -e "keycode 114 = Right NoSymbol End"
xmodmap -e "keycode 111 = Up NoSymbol Prior"
xmodmap -e "keycode 116 = Down NoSymbol Next"

This works perfectly because my Caps Lock key is remapped to Control function using Ubuntu keyboard preferences, so the left Control key is not needed. Since it is located where the Fn key is found on MacBook keyboard, switching between desktop and MacBook keyboards does not impact muscle memory.

Solution 3

Autokey worked for me. The default Autokey behavior would be: map both right ctrl+arrow and left ctrl+arrow. And I wanted only right ctrl, because I used left ctrl to navigate words.

Here is the script I used in Autokey:

output = system.exec_command('xinput query-state "AT Translated Set 2 keyboard" | grep down', getOutput=True)
# 105 is right ctrl
if 'key[105]=down' in output:
    keyboard.send_keys('<end>')
else:
    keyboard.send_keys('<ctrl>+<right>')

Note: you might have a different keyboard name. Try all of them. I had 3 devices, but only one worked

xinput list --name-only | grep -i keyb
Virtual core keyboard
Virtual core XTEST keyboard
AT Translated Set 2 keyboard

P.S. I installed Autokey from GitHub, because the package in Ubuntu Software is broken.

Share:
9,514

Related videos on Youtube

acid009
Author by

acid009

Updated on September 18, 2022

Comments

  • acid009
    acid009 over 1 year

    On Windows, I used to bind Ctrl+Left to Home and Ctrl + Right to End via ahk.

    Now I'm struggling to achieve this behavior in Ubuntu. I've tried editing /etc/inputrc:

    "\e[1;5C": end-of-line
    "\e[1;5D": beginning-of-line
    

    It works but only in the terminal window. I've also tried xmodmap:

    xmodmap -e "keycode 113=Left NoSymbol Home"
    

    but it does not work.
    The strange thing here is that if I bind to Shift + Left in xmodmap it works:

    xmodmap -e "keycode 113=Left Home"
    

    My guess here is that the default behavior of Ctrl + Left(skip words) somehow gets priority over xmodmap bindings.

    Where can I find where the default bindings are located and how to remove it? Or, maybe I could just bind needed behavior there ?

    I'm on Ubuntu 12.04

    • web.learner
      web.learner about 11 years
      Do you get xev output for the keys you want to change?
    • acid009
      acid009 about 11 years
      I do. I got keycode 113 = Left from xev output.
    • web.learner
      web.learner about 11 years
      Can you add the whole xev output please?
    • acid009
      acid009 about 11 years
      state 0x0, keycode 113 (keysym 0xff51, Left)
    • acid009
      acid009 about 11 years
      and state 0x4, keycode 113 (keysym 0xff51, Left) if pressed with Ctrl - the state is changed to 0x4 as expected
  • Kevin Bowen
    Kevin Bowen almost 11 years
    Nice. This might also be a good fit as an answer here as well askubuntu.com/questions/254424/…
  • nobody
    nobody almost 11 years
    An expanded, more generic version: askubuntu.com/a/304834/194 Does that make this question a duplicate?
  • Kevin Bowen
    Kevin Bowen almost 11 years
    It probably does, but you should still get the bounty. ;-)
  • acid009
    acid009 about 10 years
    this method does not work.
  • nobody
    nobody about 10 years
    Still works for me using Ubuntu 13.10 and AutoKey 0.90.1.
  • JeffDror
    JeffDror almost 10 years
    For me this works well for <home> and <end> but not for <pgup> and <pgdn>.
  • nobody
    nobody almost 10 years
    @JeffDror it's <page_up> and <page_down> ( code.google.com/p/autokey/wiki/SpecialKeys )
  • Tom
    Tom about 5 years
    Nice, but doesn't work when combining with SHIFT to e.g. move from beginning of line to its end while wanting to select the line content
  • Kvothe
    Kvothe over 3 years
    It says the script contains an error for me. The script contains nothing but <home>. (Ubuntu 20.04)
  • Kvothe
    Kvothe over 3 years
    @Tom, can't that be solved by adding scripts for Shift+Ctrl+Left/Right that first holds Shift and then <home> and then releases shift?