Customizing keymap

I want to customize keys in my urdu keyboard layout.
I am using Urdu (Pakistan) Keyboard with variant Arabic (Pakistan)
I want to swap the urdu alphabet ئ that is currently on “$” with ء that is currently on “u”

I found out that the keymaps are located in /usr/share/X11/xkb/symbols

I tried to modify the keymap file then saved it. but then keyboard layout settings was not loading any of the keyboard layouts in that file.

Then I restore the original file and put a custom keymap file in the symbols folder.

As a result now Add keyboard layout functionality is disabled. I’ve removed the custom keymap file and restarted the system but the Add Keyboard layout button is still disabled… :confused:

What should I do now?


somebody from Qubes OS forum referred me here and said that I’ll get a quick response from this team.

But so far it seems no body is interested in replying… :disappointed:

That is probably because customizing keymap is rarely done, so nobody knows how to do that.

Are you on Fedora Workstation 40? What Fedora Spin are you on? From your comment it looks like you tried to do an X11 change, but that wont work in Wayland.

The forums Main Page pushes thread with a lot of activity to the top. i never saw your comment so apologieze are in order for that.

Here are some things you can try Settings > Keyboard :

Actually I am using Qubes OS which is based on fedora 38 with Xfce.

I want to swap 2 keys in Urdu keyboard layout not the default one. The one on AD07 ($ on en keyboard layout) with the one on AE04 (u on en keyboard layout).

It can’t be done with simple keyboard settings.

I searched alot on Qubes OS Forum and here but couldn’t found anything suitable to my needs.

Well can you simply tell me how to add custom keyboard layout the one that is not listed in the in-built keyboard settings.

thanks alot.

You might need to use setxkbmap in Domain0. . .
Use xev command in dom0 to identify the exact keycodes for the keys you want to swap (AD07 and AE04). Press the keys one by one and note the keycode in the output.

In dom0, create a script (e.g., with the following content, replacing KEYCODE1 and KEYCODE2 with the actual keycodes you identified:

setxkbmap -layout "ur" -option "grp:win_space_toggle" -option "map:AE04=KEYCODE1,AD07=KEYCODE2"

This script sets the Urdu layout, enables the Windows key as a toggle for switching layouts (optional), and swaps the keycodes using the map option.

Make the script executable: chmod +x

There is another way where you can create a custom X11 keyboard layout configuration file. . .

I need a few minutes to put it together, I have some old scripts that I need to condense ans maybe they work? Either way you will need to use a script.

Keyboard layout files are stored in /usr/share/X11/xkb/symbols/

Copy the existing layout file for Urdu from the system directory to a new file in the same directory.

sudo cp /usr/share/X11/xkb/symbols/pk /usr/share/X11/xkb/symbols/pk_custom

Open the copied layout file with a text editor.

sudo nano /usr/share/X11/xkb/symbols/pk_custom

Look for the section defining the keys you want to swap. It might look something like this (you will need to adapt this to match the specific layout details of your Urdu layout):

key <AD07> { [ dollar, asciicircum,      dollar,      asciicircum      ] };
key <AE04> { [ u, U,                    u,           U                ] };

Swap the key definitions. Modify them as follows:

key <AD07> { [ u, U,                    u,           U                ] };
key <AE04> { [ dollar, asciicircum,      dollar,      asciicircum      ] };

Modify the sudo nano /etc/X11/xorg.conf.d/00-keyboard.conf and add :

Section "InputClass"
    Identifier "system-keyboard"
    MatchIsKeyboard "on"
    Option "XkbLayout" "pk_custom"

Restart the X server or reboot the machine.

@shamsuddin82 This might be easier than the first comment . . . QubesOS might be based on Fedora but there are fundamental differences, this “should work” but we can’t be too much help outside of this. I don’t run QubesOS, so it’s hard to replicate. Good luck.

Added f38, keyboard, xfce

I followed your instructions. Modified 00-keyboard.conf file then restarted the system…

Now my default keyboard is urdu while my login credentials are in English. And I can’t find any way to change the language.

How am I suppose to login now?

Can you select the keyboard at the login screen?

No such option available…

Which one did you do, the first or second script?

The second one. Created pk_custom file. Modified it, then modified the 00-keyboard.conf file, then restarted the system.

Your going to have to get to a TTY from the log in screen press Ctrl + Alt + F2 to make the changes, but if you can “guess” the the keys you used you could still log in.

Eitther way, when you get back in you can go back to /etc/X11/xorg.conf.d/00-keyboard.conf and make the changes to it :

Section "InputClass"
    Identifier "system-keyboard"
    MatchIsKeyboard "on"
    Option "XkbLayout" "us" # You need to change this here to what you need at login

I feel bad, because I cannot replicate this for you. I’m not on QubesOS and am short on time today. :frowning_face:

I reverted the changed and logged back in.

Sorry to waste your time. It seems this system-keyboard identifier changes the default keyboard.

I don’t want to change the default keyboard. I just want to add the custom keyboard layout in the keyboard layouts list.

But it seems simply putting custom keymap file in /usr/share/X11/xkb/symbols folder doesn’t work

:frowning_face: Sorry for the experience, it’s not a waste of time. We tried. :handshake:t5:

1 Like

Well I am certainly not sorry for the experience. Even if I didn’t got the solution I wanted, still I learned something useful.

Thanks a lot for that.

But I am not giving up yet on this issue. I’ll keep searching for the solution.

1 Like

BTW I tried this:

Replaced KEYCODE1 & KEYCODE2 with my required keycodes. Then executed the script file but nothing happened.

My problem solved!

The solution was rather simple

I was changing keymapping of an existing keyboard layout in Dom0 and testing the results inside VMs.

That’s where the problem was. Now I found out that I have to change the keymappings in VMs too.

Thanks alot for all your support.