Remap an arbitrary key on keyboard to another output

All Gurus once were Newbies
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. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read this

Remap an arbitrary key on keyboard to another output

Postby ecscott on Sun Jul 29, 2012 1:31 am

I have a calculator key on my new laptop, right next to the control key. My muscle memory from my old keyboard keeps hitting calculator key instead of the control. Until I find a compelling use for the key I'd ideally like to have it as an additional control. Hopefully having multiple keys doing the same thing on the keyboard is possible?

I'm asking how to change any key on the keyboard to another because there's a few other changes I'd like to make in the future (there's a few other shortcut keys besides calculator). I need to know how to set this up this change permanently and reversibly (in case something goes terribly wrong)

I am a complete newbie and would prefer it explained like I'm five. However, if one of the steps ends up being "go read this tutorial on editing these kinds of configuration files," that would be fine too--I installed Linux in part to learn how to configure arbitrary things about my computer.

edit: Changed "Change" in subject to remap, per further googling. Still hoping for step-by-step instructions, however. "xmodmap" looks like something I'll have to use?
ecscott
Level 1
Level 1
 
Posts: 7
Joined: Sun Jul 29, 2012 1:15 am

Linux Mint is funded by ads and donations.
 

Re: Remap an arbitrary key on keyboard to another output

Postby Jaws on Sun Jul 29, 2012 9:59 am

Not sure if you're running the gnome DEs but in KDE there are settings under System Settings -> Hardware -> Input Devices -> Keyboard where you can change keyboard models, layouts (including shortcuts for switching layout, and configure keyboard options. Maybe this will help.
Jaws
Level 1
Level 1
 
Posts: 49
Joined: Thu Jul 19, 2012 10:56 am

Re: Remap an arbitrary key on keyboard to another output

Postby ecscott on Sun Jul 29, 2012 12:12 pm

Jaws wrote:Not sure if you're running the gnome DEs but in KDE there are settings under System Settings -> Hardware -> Input Devices -> Keyboard where you can change keyboard models, layouts (including shortcuts for switching layout, and configure keyboard options. Maybe this will help.


I'm pretty sure I'm running Mate. I don't quite remember what I ended up installing, what's the quick and dirty way to check? (I have a program called eye of mate, which is why I'm guessing I have Mate installed).
ecscott
Level 1
Level 1
 
Posts: 7
Joined: Sun Jul 29, 2012 1:15 am

Re: Remap an arbitrary key on keyboard to another output

Postby ecscott on Sun Jul 29, 2012 12:36 pm

I think I'm making progress, I found http://askubuntu.com/questions/24916/how-do-i-remap-certain-keys to be pretty much what I'm looking for.

Using xev, here is the output for "ctrl" and then, immediately after, "calc":

Code: Select all
KeyPress event, serial 33, synthetic NO, window 0x3600001,
    root 0xaf, subw 0x0, time 79820428, (374,-425), root:(377,82),
    state 0x0, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 33, synthetic NO, window 0x3600001,
    root 0xaf, subw 0x0, time 79820533, (374,-425), root:(377,82),
    state 0x4, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

FocusOut event, serial 33, synthetic NO, window 0x3600001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 33, synthetic NO, window 0x3600001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 33, synthetic NO, window 0x0,
    keys:  4294967265 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   

FocusOut event, serial 33, synthetic NO, window 0x3600001,
    mode NotifyNormal, detail NotifyNonlinear


...the output for the calc key is really confusing to me. I'm not sure how that would fit into the xmodmap editing instructions that are listed in the link apply to the output I actually got.

edit: updated pasted xev output to a possibly more relevant snippet. Seems to be double-reporting keypresses in the output?
ecscott
Level 1
Level 1
 
Posts: 7
Joined: Sun Jul 29, 2012 1:15 am

Re: Remap an arbitrary key on keyboard to another output

Postby Lord_Eager on Sun Jul 29, 2012 12:59 pm

This is not what he's searching for.
It's very easy to achieve what you ask for.

First thing you need to know is the key code for the special key you want to configure, to achieve that write in a terminal:
xev

a small window will open and since then every key you press, or movement of mouse is recorded and print on terminal, so don't move mouse a press the key you are interested to know the code, and suddenly some values will appear in the terminal window. The one you are interested in is key code. Keep in mind that value or write it down somewhere.

Now write in terminal:

xmodmap -pke > $HOME/.keymap.conf
and press Enter.
Then:
sudo nano $HOME/.keymap.conf

search for the key code you previously wrote down, and write after the "=" :
Code: Select all
Control_L NoSymbol Control_L NoSymbol Control_L


If your keycode instead is not there in the list it means that the key is not mapped in the layout you choose, so try to add the line you need, something like:
keycode XX = Control_L NoSymbol Control_L NoSymbol Control_L
where "XX" is the key code you previously wrote down.

Save it by pressing Ctrl+o and exit by pressing Ctrl+x.
Now write in the terminal:
xmodmap $HOME/.keymap.conf

And check if your special key acts like Ctrl.

If it works fine you should in the end write a small script to execute at startup, so that you will have your key mapped every time you start your machine up.

Write in a terminal:

sudo nano /etc/init.d/keymap.sh


and copy inside the empty file modifying "user" with your account name:
Code: Select all
#!/bin/sh
PATH=/home/"user"/.keymap.conf
#Execute key re-mapping
xmodmap $PATH


save the file and exit.

Last thing to do is to write in terminal:
sudo update-rc.d keymap.sh defaults


Reboot machine and pray :D
it should work, however if it doesn't we could try to understand what's the matter.
I hope it's enough "5yrs old style" :lol:
Lord_Eager
Level 3
Level 3
 
Posts: 184
Joined: Tue Jul 17, 2012 11:59 am

Re: Remap an arbitrary key on keyboard to another output

Postby ecscott on Thu Sep 20, 2012 3:13 pm

Code: Select all
KeymapNotify event, serial 33, synthetic NO, window 0x0,
    keys:  2   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   

FocusOut event, serial 33, synthetic NO, window 0x3600001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 33, synthetic NO, window 0x3600001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 33, synthetic NO, window 0x0,
    keys:  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   0   

FocusOut event, serial 33, synthetic NO, window 0x3600001,
    mode NotifyNormal, detail NotifyNonlinear


Thanks for the fantastic answer! It's been a few months, but I got reannoyed enough at this problem to try implimenting your solution.

Using xev, I can get other keys to give key codes, even from that same row of proprietary keys, but the calculator key doesn't?

when I try the key right above it, a printer key, I get something completely different:

Code: Select all
KeyPress event, serial 33, synthetic NO, window 0x3600001,
    root 0xaf, subw 0x0, time 57835909, (56,-17), root:(59,53),
    state 0x0, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyPress event, serial 33, synthetic NO, window 0x3600001,
    root 0xaf, subw 0x0, time 57835910, (56,-17), root:(59,53),
    state 0x4, keycode 33 (keysym 0x70, p), same_screen YES,
    XLookupString gives 1 bytes: (10) ""
    XmbLookupString gives 1 bytes: (10) ""
    XFilterEvent returns: False

KeyRelease event, serial 33, synthetic NO, window 0x3600001,
    root 0xaf, subw 0x0, time 57836047, (56,-17), root:(59,53),
    state 0x4, keycode 33 (keysym 0x70, p), same_screen YES,
    XLookupString gives 1 bytes: (10) ""
    XFilterEvent returns: False

KeyRelease event, serial 33, synthetic NO, window 0x3600001,
    root 0xaf, subw 0x0, time 57836050, (56,-17), root:(59,53),
    state 0x4, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False


When I hit the calculator key, another thing happens: I get a pop up dialog that states: "Couldn't execute command: gcalctool
Verify that this is a valid command."

So I went and installed gcalctool, the key now launches the calculator, and using xev gets me this readout:

Code: Select all
VisibilityNotify event, serial 33, synthetic NO, window 0x3600001,
    state VisibilityPartiallyObscured

FocusOut event, serial 33, synthetic NO, window 0x3600001,
    mode NotifyNormal, detail NotifyNonlinear

PropertyNotify event, serial 33, synthetic NO, window 0x3600001,
    atom 0x186 (_NET_WM_ICON_GEOMETRY), time 58314031, state PropertyNewValue


Stuck right at the beginning!
ecscott
Level 1
Level 1
 
Posts: 7
Joined: Sun Jul 29, 2012 1:15 am

Re: Remap an arbitrary key on keyboard to another output

Postby ecscott on Sun Sep 23, 2012 4:53 pm

A single bump. I am so close it hurts! But not quite there yet.
ecscott
Level 1
Level 1
 
Posts: 7
Joined: Sun Jul 29, 2012 1:15 am

Re: Remap an arbitrary key on keyboard to another output

Postby sectionq on Fri Jan 25, 2013 6:12 am

Hi guys, I hope someone still sees this as it's an old post. I originally put this on the newbies section but it was suggested that it was possibly a bit much for there, so hopefully it'll work better here. Anyway, I've been following the instructions for remapping and it's all working well but I'm struggling to get the keymappings to stick after I reboot.

The problem seems to be that when I simply put this in the keymap.sh file (q is my user name)
#!/bin/sh
PATH=/home/q/.keymap.conf
#Execute key re-mapping
xmodmap $PATH


and then write in terminal "
sudo update-rc.d keymap.sh defaults
"
And it tells me...

update-rc.d: warning: /etc/init.d/keymap.sh missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
System start/stop links for /etc/init.d/keymap.sh already exist.


So not knowing what I'm doing I add in what I figure to be LSB information at the start

### BEGIN INIT INFO
# Provides: scriptname
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
#!/bin/sh
PATH=/home/"user"/.keymap.conf
#Execute key re-mapping
xmodmap $PATH

I managed to get rid of the warnings but it stiil tells me "
System start/stop links for /etc/init.d/keymap.sh already exist.
"

So after a reboot my keymappings are all lost.

Any ideas?

Thanks

Jamie
sectionq
Level 1
Level 1
 
Posts: 9
Joined: Thu Jan 24, 2013 6:08 pm

Linux Mint is funded by ads and donations.
 

Return to Newbie Questions

Who is online

Users browsing this forum: Crackington and 23 guests