I Got Tired of the Way I Type Parentheses on a QWERTY Keyboard
Tags: linux, keymap, qwerty
Published: 2024-06-04 15:57:50

<h2 id="i-was-used-to-azerty-layout">I was used to AZERTY layout</h2>
<p>I was forced to use AZERTY keyboards because, they are the default
layout in my region. Recently I acquired a QWERTY keyboard. I’m getting
used to it but, there are some keys that shouldn’t be placed the way
they are. My first and major issue was the parentheses key. To type left
parentheses you need to hold the SHIFT_KEY and press 9. I use left
parentheses quite a lot, I got tired, and tried to change it.</p>
<h2 id="heres-how-i-changed-my-keymaps">Here’s how I changed my
keymaps</h2>
<p>I should mention that I’m on Fedora, this should work on all Linux
machines (sorry Windows, and Mac users).</p>
<ul>
<li>On your home directory, create a file and name it “.Xmodmap”.</li>
<li>Open the file in your text editor.
<ul>
<li>Here is the basic syntax:</li>
</ul>
<pre><code>keycode &#39;Number&#39; = &#39;Keysystem&#39; [SHIFT] &#39;Keysystem&#39;
keycode 59 = comma parenleft</code></pre>
<ul>
<li>The keycode 59 coresponds to the comma and less key (, &amp;
&lt;).</li>
<li>The keysystem is what you want it to type e.g: comma, f,
slash…etc.</li>
<li>The second argument is what is typed when holding the SHIFT_KEY
(don’t write ‘[SHIFT]’).</li>
</ul></li>
<li>Get the keycodes however you want. I used a tool called ‘xev’.
<ul>
<li>In the terminal run ‘xev’. Press a key, it’ll give you this:</li>
</ul>
<pre><code>KeyRelease event, serial 38, synthetic NO, window 0x2000001,
root 0x4a4, subw 0x0, time 2789210, (905,497), root:(1006,637),
state 0x0, keycode 32 (keysym 0x6f, o), same_screen YES,
XKeysymToKeycode returns keycode: 19
XLookupString gives 1 bytes: (6f) &quot;o&quot;
XFilterEvent returns: False</code></pre>
<ul>
<li>I typed ‘o’ (not zero), and voila keycode 32, and keysystem, ‘o’
(line 3).</li>
</ul></li>
<li>When you’re done, run the script in the terminal</li>
</ul>
<pre><code>$ xmodmap ~/.Xmodmap</code></pre>
<h2 id="but-youll-have-to-run-the-command-each-time-you-login">But
you’ll have to run the command each time you login</h2>
<p>I ran the command, and it was working. I was easily typing
parentheses because, I switched it with less and greater ‘&lt; &amp;
&gt;’. But when I restarted the computer, my modifications were gone. I
was back at doing chores typing parentheses. So now, every time I login,
I have to open the terminal, and run the command.</p>
<p>Just kidding, you can make the command run automatically upon login.
There are multiple ways on how to do it. I tried some, but only one
worked for me.</p>
<ul>
<li><a
href="https://www.baeldung.com/linux/run-script-on-startup">This</a>
article explores 4 ways on how to do it.</li>
<li><a
href="http://xahlee.info/linux/linux_xmodmap_tutorial.html">This</a> one
here explains the whole process (change the keymapping and auto execute
it) in-depth.</li>
<li>There is also a <a
href="https://www.youtube.com/watch?v=jcE8U1lG514&amp;t=377s&amp;ab_channel=SpartanCC">video</a>.</li>
</ul>
<p>However, what worked for me was over on <a
href="https://stackoverflow.com/questions/8247706/start-script-when-gnome-starts-up/8290652#8290652">stackoverflow</a>.</p>
<ul>
<li>Basically, make a bash scrpit (‘example.sh’), put the command in
it:</li>
</ul>
<pre><code>#!/bin/sh
xmodmap ~/.Xmodmap</code></pre>
<p>and make it executable</p>
<pre><code>$ chmod +x /path/to/example.sh</code></pre>
<ul>
<li>Head over to this directory (/etc/xdg/autostart)</li>
<li>Create a file with ‘.desktop’ extension.</li>
<li>Put this code in it:</li>
</ul>
<pre><code>[Desktop Entry]
Name=MyScript
GenericName=A descriptive name
Comment=Some description about your script
Exec=/path/to/example.sh
Terminal=false
Type=Application
X-GNOME-Autostart-enabled=true</code></pre>
<ul>
<li>Don’t forget to replace /path/to/example.sh with the actual
path.</li>
<li>Reboot your system, and there you have it.</li>
</ul>
<h2 id="conclusion">Conclusion</h2>
<p>I tried multiple methods that didn’t work for me. They might work for
someone else. I think that curly braces get used more than square
brackets, so that might have to change. Also, backslash could switch
with asterisk. However, imagine the reaction of someone using my
computer, priceless I know.</p>