How to remap key on startup

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
jgradyc

How to remap key on startup

Post by jgradyc »

I want to switch the PgUp and the Delete keys. I have done this successfully on my laptop from the terminal, but I have not been successful in getting these commands to automatically run on startup. To remap the keys, I used these commands.

xmodmap -e "keycode 112 = Delete"
xmodmap -e "keycode 119 = Prior"

This successfully switches the keys, but I have to re-enter these commends after rebooting. I then tried to follow instructions to create something called a script to run at start to make these changes permanent. The instructions to do this are everywhere on the internet, but none seem to be the same! :?: I tried duplicating some of the instructions, but they didn't work.

I guess my question is: How do I create this script or whatever it's called and how do I save it to autorun every time the computer boots up? Thanks.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
bigj231

Re: How to remap key on startup

Post by bigj231 »

I think what you're looking for is the rc.local file. You can view it with:

Code: Select all

nano /etc/rc.local
It shouldn't have any commands unless you changed it. Just add those commands to that file, before the "exit 0" and they will be run at startup. You will have to open it with root privileges to edit it. You can also use gedit instead of nano.
jgradyc

Re: How to remap key on startup

Post by jgradyc »

Thanks. I found another approach that was sooooo easy!! (Note: in the following instructions, I had already determined the keycode number and names of the Delete and PageUp keys.)

In Linux Mint 14...
1. Click menu
2. Click preferences
3. Scroll down list to Startup Applications... click on Startup Applications
4. On the new window that opens up, click "add"
5. On the new window that opens, put a descriptive name in "Name". I entered "Remap Prior to Delete"
6. In Command box, I entered: xmodmap -e "keycode 112 = Delete"
7. In Comments box, I entered: This remaps the PageUp key to a Delete key on startup
8. Next, I clicked "add" to close that window.

***NOTE*** Keycode 112 is the Page Up keycode on my keyboard. Your keyboard might be different. You have to find the keycode for each key using the XEV command.

Then, I repeated steps 4 through 8 as follows
Name: Remap Delete to Prior
Command: xmodmap -e "keycode 119 = Prior"
Comments: This remaps the Delete key to be a PageUp key
Click "add"

***NOTE*** Keycode 119 is the Delete keycode on my keyboard. Your keyboard might be different. You have to find the keycode for each key using the XEV command.

Then, click "close" to close the window.

When I rebooted, it worked fine.
jgradyc

Re: How to remap key on startup

Post by jgradyc »

bigj231 wrote:I think what you're looking for is the rc.local file. You can view it with:

Code: Select all

nano /etc/rc.local
It shouldn't have any commands unless you changed it. Just add those commands to that file, before the "exit 0" and they will be run at startup. You will have to open it with root privileges to edit it. You can also use gedit instead of nano.
Thanks again. I'm pretty sure this is what I did a few months ago before I reinstalled Linux Mint. I just couldn't find a reference to gedit \etc\rc.local

I'll remember this next time I have to add a script to run automatically. Thanks again.
bigj231

Re: How to remap key on startup

Post by bigj231 »

You can use nano on almost any system, that's why it's often listed in tutorials. KDE systems will not have gedit, so you could use kate instead. A lot of people swear by vi, at least as many swear at it. Same with emacs.
You can use whatever text editor you want, but gedit or kate are easiest for small to middling edits IMO.
Locked

Return to “Beginner Questions”