How to map a broken key to a replacement?

Zorin Lite 16.2 XFCE:
On both my mum's and my old HP laptops, the Down keys are physically broken (in any OS). Obviously the long term solution is to get them physically repaired but I was wondering if in the meantime I could remap to an alternative or combination, e.g. Shift+Up to get Down.
I've seen a few related posts elsewhere but they all suggest different methods and I'm not sure which, if any, would be right on Zorin Lite (and I don't want to bork anything else: right now every other key works exactly as it should).
And if there's a GUI way to do it, that would be easier for me than CLI.

1 Like

You could look through keyboard shortcuts in the settings and possibly reassign it there.

1 Like

In XFCE's Settings > Keyboard > Application Shortcuts, you can set up key combinations but, as far as I can tell, just to trigger applications. In Layout, you can change the Compose key, and the entire layout. But not just one key of your choice.

1 Like

Probably you can use the Down arrow of the numpad section of your keyboard, on the right of Enter button. In my case, the Down arrow is on 2 button but in can be on 8 for you. The problem is that I tried to use that Down button but I wasn't able to make it do what it should, whatever I pressed (Shift, Fn, Ctrl, Alt) together with that was only writing 2 :face_exhaling:. I hoped that at least the on-screen keyboard had arrows but it doesn't :unamused:. As last, I'd suggest to create a custom keyboard shortcut but I don't know the command to execute Down button action.

Input Remapper, available via a deb file, will let you remap any key. You could make the right Ctrl key do down arrow.

Number lock is on for the number pad. It can be disabled by the keyboard and in the bios.

@Luca_Pavan & @337harvey , both machines are laptops without number pads.

@TabNumlock that program looked interesting until I read this:

Note that for the Input Remapper to work correctly, you need to physically press the mapped button. For instance if you mapped key to <Ctrl+C>, the remapping won’t work until you press the key. Any third party program that simulates pressing of key through software solutions may fail to invoke <Ctrl+C> mapping.

And:

If your fingers can't type it on your keyboard, input-remapper can't inject it.

I tried anyway using Onboard to mimic the Down key, but Input Remapper didn't register it.

1 Like

you may want to take a look at xmodmap. Here is a tutorial on changing the keys and ensuring the modified keymap starts: https://linuxconfig.org/reprogram-keyboard-keys-with-xmodmap

Hope this is what you are looking for. When you use the terminal to type out the xmodmap -pke command, you will notice Control_R around keycode 105 and the down arrow is around 116. Hopefully this will allow you to do what you intend, until the keyboard can be replaced.

2 Likes

How about plugging in a KB?

No. I think because it will only accept input from the keyboard you're trying to remap (selected in step 1).

The link I provided says to create an xmodmap file in your home directory. Then you edit the values as necessary....so the entry keycode 105=Down NoSymbol Down, instead of Control_R. Then you add a line to the bottom of bashrc so that it loads any time you login or access the terminal. It doesn't require you to press any key, rather define by the key name. It will be system wide.

1 Like

That was a reply to TabNumlock: trying his idea was quicker so I tried that first before xmodmap.
Now I've tried xmodmap.
Because I use right ctrl all the time, I decided to try a key combination for another key.
Due to its location on the keyboard I decided to use the End key.
I followed the instructions in the tutorial and found out the existing key mapping.

keycode 88 = KP_Down KP_2 KP_Down KP_2
keycode 87 = KP_End KP_1 KP_End KP_1

I thought of trying Ctrl or Fn or Alt or Alt Gr + End to get down, but after 10 minutes of trying to understand opaque or contradictory online info as to what actual keys on my keyboard equated to Mode_switch and ISO_Level3_Shift, I gave up & said "f#ck itm just use Shift". Which is the second position, supposedly. So I modified the End key entry to:

keycode 87 = KP_End KP_Down KP_End KP_1

Then I saved and carried out the remaining steps in the tutorial.
Tried Shift+End a couple times to go down in the browser. Nothing.
So I logged out and back in again to see if that would make it work. Tried going down in the browser. Again, nothing.
Trying it in the edit window here, instead of going down, it selected everything from the cursor to the end of the line. Doh! Of course. Which is why I wanted a different modifier key in the first place.
In a minute I'll try remapping a key without use of a modifier, one I never use like insert, and post back how that goes.

1 Like

Nope. Mapping to Insert (first position) doesn't work either, even after logging out and back in again.

Maybe trying the right alt....I don't know how you use your keyboard. It really depends on your use and what is not utilized. Since right control is out of the question, if you don't code, you may want to try the ` key or possibly the |....While these aren't ideal because of the distance and change in hands, it depends on how you use the computer. Maybe adding it to the shift position of the up arrow?

The info on the xmodmap method says that it doesn't work in certain desktop environments. Does anyone know if it actually works in Zorin Lite XFCE?

Yes it works perfectly well in XFCE (though ~/.xmodmap may need to be added to startup).

How would I do that? In "Session and Startup"? Somewhere else?

If you read the link I shared, running echo xmodmap ~/.Xmodmap >> ~/.bashrc adds what you need to the bashrc and loads it on boot. All of this is explained in the link I provided.

I did read the link. I did carry out step 4. (I just wasn't sure if "so it gets executed whenever a new terminal or shell is opened" and "added to startup" meant the same thing.)
But I'll carry it out again, just in case. Still nothing.
Ah, "on boot". So maybe just logging out isn't enough. Will reboot and see what happens.
EDIT: No, rebooting didn't work. Insert key seems completely unaffected.

.bashrc is loaded on session start as well as when the terminal is opened. Any one of these actions should load the xmodmap as long as it is named the same as what is in the command ".Xmodmap" and it is located at ~/.