4

The Return key in my keyboard is broken, so I have chosen to make my PgDn key to act like the Return key. Now I learned how to do this using 'xmodmap'. The command I have to run is:

xmodmap -e 'keycode 117 = Return'

But I have to run this command everytime I reboot. I googled around and found that placing this command in the /etc/rc.local file should run it automatically at start-up. However, it does not work.

Can anyone tell me how can I execute this command when I boot up? I am using Ubuntu 14.04.

Radu Rădeanu
  • 169,590
johngreen
  • 149
  • Where exactly did you place your command in the file? After or before exit 0? – jobin May 09 '14 at 07:03
  • @JacobVlijm I don't see anything to do with the GUI in this question, and your answer isn't a GUI answer.. – Seth May 10 '14 at 03:24
  • @Seth my answer is a GUI answer, and does not work when logging in via command line, while the supposed duplicate Karel mentioned explicitely asked for a solution that also works for non-GUI. – Jacob Vlijm May 10 '14 at 21:05

2 Answers2

5

Although you asked for a solution on startup, this might do what you want as well: to run a command on login, on user level, here is a simple one:

For example, to set the PageDown key as Return key on login:

Create a .desktop file as below, save it in ~/.config/autostart

[Desktop Entry]
Name=Set Keyboard
Exec=xmodmap -e 'keycode 117 = Return'
Terminal=false
Type=Application

Copy the text above, paste it into an empty textfile (gedit), save it as set_keyboard.desktop (or anything_else.desktop) in ~/.config/autostart

Jacob Vlijm
  • 83,767
3

The easiest way to run commands at on user login (which is the best way to accomplish what you want) is to add the command to the .profile file (located in /home/[user]/). You want to add the command to the end of the file. For example:

[user@host ~]# nano .profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# Remap Return key to Page Down on login
xmodmap -e 'keycode 117 = Return'

You should be able to logout and log back in to make this change take effect. However, it may be best just to reboot (to fully test it out).

ChrisR.
  • 527
  • 4
  • 7