<p>In this episode I talk about how I tried to implement an idea that my son had when we were talking one day. I was complaining about file names with spaces in them, and he asked what if the computer automatically changed the spacebar so that it made underscores whenever somebody was trying to save a file? I thought this was a great idea. I even thought of a way implement it, though not quite as magically as he had envisioned. My solution involves the use of the command-line tools <code>xev</code> and <code>xmodmap</code>, and one <a href="https://www.jezra.net/projects/blather">blather</a> voice prompt to launch the <code>xmodmap</code> command that will remap the spacebar to make underscores instead. Maybe somebody a whole lot smarter than me can figure out how to make this happen automatically whenever a save dialog box is open.</p>

<p>First you need to find the keycode for your spacebar. Run the <code>xev</code> command and then press the spacebar to see which key code it is. Here's the output on my laptop:</p>

<pre>KeyPress event, serial 48, synthetic NO, window 0x4e00001,
    root 0xc0, subw 0x0, time 116149126, (-739,-226), root:(448,358),
    state 0x0, keycode 65 (keysym 0x20, space), same_screen YES,
    XLookupString gives 1 bytes: (20) " "
    XmbLookupString gives 1 bytes: (20) " "
    XFilterEvent returns: False
</pre>

<p>As you can see, my spacebar has the keycode of "65." Now we use <code>xmodmap</code> to reassign keycode 65 to make underscores:</p>

<pre>xmodmap -e "keycode 65 = underscore"</pre>

<p>Now to test it out. While <code>xev</code> is running, press spacebar. Notice that now when the spacebar is pressed it makes an underscore:</p>

<pre>KeyPress event, serial 57, synthetic NO, window 0x2600001,
    root 0xc0, subw 0x0, time 116190619, (-520,-247), root:(667,337),
    state 0x0, keycode 65 (keysym 0x5f, underscore), same_screen YES,
    XLookupString gives 1 bytes: (5f) "_"
    XmbLookupString gives 1 bytes: (5f) "_"
    XFilterEvent returns: False
</pre>

<p>And to change it back:</p>

<pre>xmodmap -e "keycode 65 = space"</pre>

<p>Now whenever I want to change the spacebar to make underscores or switch it back, I speak one of the following commands, which are in my blather configuration file.</p>

<pre>
MAKE UNDERSCORES: xmodmap -e "keycode 65 = underscore"
MAKE SPACES: xmodmap -e "keycode 65 = space"
</pre>

<h2>Links</h2>

<ul>
	<li><a href="https://linux.die.net/man/1/xmodmap">xmodmap man page</a>: <code>xmodmap</code> is a utility for modifying keymaps and pointer button mappings in X</li>
	<li><a href="https://linux.die.net/man/1/xev">xev man page</a>: use <code>xev</code> print contents of X events</li>
</ul>

<h2>Video Demonstration</h2>

<p><a href="https://www.youtube.com/embed/hKEax8IqxAU">https://www.youtube.com/embed/hKEax8IqxAU</a></p>

