Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am looking for general instructions on remapping keys.

Can someone tell me how to remap F9 to PrtScr and F10 to ScrollLock button?

I have looked through every thread here and none of the suggestions worked.

I am using a Swedish keyboard setup and Ubuntu 12.04.

share|improve this question
3  
Have you tried using the Search function selecting the "votes" tab/button to filter results at AskUbuntu? The link at end of this comment may help you understand Argusvisions's answer and i will post one to in order to try and help. Here is one answer from search results when searching for "rempap key" using the advice just given - askubuntu.com/a/24930/102029 –  geezanansa May 16 '13 at 20:38

2 Answers 2

This answer has been mostly made up using the information from the first three steps of this Ask Ubuntu answer and this Ubuntu Forums thread to which it links/refers to. This other Ask Ubuntu answer was very helpful to. So all credit to NES, llazarte, bodhi.zazen and Argusvision.

To simply swap two keys functions: From Terminal run xev and then press F9 which would give something like Terminal window showing F9 KeyPress event

Doing the same for PrtSc did not give any output in xev for me (or i could not find the "KeyPress event") so i used Argusvision's advice for using the Custom Shortcuts in All Settings but doing so in order to disable PrtSc as screenshot button by reassigning as Shift + Alt then tried pressing again which gave me keycode 107 for PrtSc in xev like so Terminal window showing PrtSc KeyPress event

Repeating the process for all four keys gave me

  • F9 = keycode 75
  • PrtSc = keycode 107, action Print
  • F10 = keycode 76
  • Scroll Lock = keycode 127, action Pause

To change a keys function we need to know the keycode of the NEW key being pressed and the "action" of the OLD or existing key for that function.

Now that we have the key codes for identifying the keys we now make the system do what we want by using xmodmap and as we know F9 has "keycode 75" and PrtSc has the action of "Print" all we need to do is
xmodmap -e "keycode 75 = Print"
to make the F9 key behave as if the PrtSc key has been pressed. i.e. the keycode stays the same but pressing the F9 key will have different results.
Using xev with Scroll Lock also gave
Terminal window showing Scroll Lock KeyPress event

which confirms the "action" for the Scroll Lock key is "Pause" so for making the F10 act as Scroll Lock trying
xmodmap -e "keycode 76 = Pause" should give the desired results.
That is until you log out or shutdown etc so what we have to do after confirming the commands
xmodmap -e "keycode 75 = Print"
xmodmap -e "keycode 76 = Pause"

do give the desired results is sort out SysRec which is modified PrtSc and swap over the other buttons so we do not have multiple instances of same key action . Adding
xmodmap -e "keycode 107 mod1 = F9 Sys_Req"
should swap F9 to where PrtSc was keeping the modified SysReq (Alt + PrtSc) again we can use xev to help verify this.
Swapping the Scroll Lock and F10 buttons is easier xmodmap -e "keycode 127 = F10"

After making sure that when running
xmodmap -e "keycode 75 = Print"
xmodmap -e "keycode 107 mod1 = F9 Sys_Req"
xmodmap -e "keycode 76 = Pause"
xmodmap -e "keycode 127 = F10"

does indeed do what is intended all that is left to do is get this happening at startup time. To do this run
xmodmap -pke|egrep -e '(F9|Print)'
which gave me
some more text
we are only interested in the keycodes 75 and 107. Do the same for
xmodmap -pke|egrep -e '(F10|Pause)'
which gave me
even more text
and we are only interested in the keycodes 76 and 127.

Create a new text document with your favourite text editor copy and paste the relevant information

keycode 75 = Print NoSymbol Print
keycode 107 = F9 Sys_Req F9 Sys_Req
keycode 76 = Pause NoSymbol Pause
keycode 127 = F10 NoSymbol F10

naming the file as .Xmodmap and saving it in your Home directory would allow you to run the changes simply by logging on after rebooting.

share|improve this answer
    
Good answer. And better researched. +1 –  Argusvision May 17 '13 at 12:09

Go to System Settings > keyboard > Custom Shortcuts. Here you can assign a command to any key or set of keys. Click the add (+) button. In the window that pops up, Name = Print Screen ; Command = gnome-screenshot. After you've created it, click on the line to the right of the name where it says "Disabled". That should change it to "New Accelorator" Just press F9.

Still looking for scroll lock.

After a little looking, I found an answer for scroll lock. I got started on this answer from what I found here. You should be able to apply it to any set of keys using xmodmap from the terminal. Edit: You can also read more about Xmodmap here

Take a look at the output of xmodmap -pke | grep F10.
Mine is:

keycode  76 = F10 F10 F10 F10 F10 F10 XF86Switch_VT_10  

This means my F10 key is keycode 76. Yours maybe different since you are using a different layout.

So I should be able to assign scroll lock to F10 with the following command:

xmodmap -e "keycode 76 = Scroll_Lock"  

You will need to insert the "keycode" you found for your F10 key.

You could also look through man xmodmap and xmodmap --help for additional options.
For example, xmodmap -pke lists your keymap table as expressions. That way you can locate the expressions assigned to other keys as well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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