How to temporarily disable aa key on the keyboard after pressing it?

I spilled beer in my mechanical keyboard and ever since it tends to repeat the "a" key whenever I press it (yes, I've cleaned it several times, used aalcohol, etc.). I tried to mitigate this issue using "bounce keys", but this feature temporarily disables all keys after they aare pressed. In other words, "bounce keys" interferes with my ability to type quickly whenever I need to type a word with a repeated letter (< like "t" in the word "letter") or repeaaatedly press backspace quickly.

(ok I won't leave the repeats in the remaining text, but you can see that it occurs with maadenning frequency)

In case it helps, I used xev to determine exactly what sequence of commands the OS is receiving and it looks like each time "a" repeats itself it is because the keyboard is sending the desired sequence multiple times (KeyPress followed by KeyRelease, then KeyPress followed by KeyRelease again). In other words, the key isn't sticking in the "KeyPress" state. It is repeating itself as if I pressed and released it multiple times.

I've seen other people ask this same question, but the solutions are not actually the one I'm seeking. For example, the solution proposed in the first answer to this question disables autorepeat, but that won't work for me because "a" isn't becoming stuck in the "Pressed" state. The second answer in that same question doesn't work either because it disables the entire keyboard after the problem key is pressed. I just want to temporarily disable the "a" key and only the "a" key for a very brief period of time (~50ms).

Fortunately, I rarely need to repeat the letter "a" when typing, so even a solution that uses something like autocorrect would work for me. Preferably, I'd like to use a solution that uses xbindkeys though because I'm already using that package to remap my mouse buttons.

EDIT: In response to a comment below, here are the outputs of 'xinput list' and 'xev':

$ xinput list
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ SINOWEALTH Game Mouse                     id=9    [slave  pointer  (2)]
⎜   ↳ EST Gaming keyboard                       id=12   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Power Button                              id=7    [slave  keyboard (3)]
    ↳ SINOWEALTH Game Mouse Keyboard            id=10   [slave  keyboard (3)]
    ↳ EST Gaming keyboard                       id=11   [slave  keyboard (3)]
    ↳ EST Gaming keyboard                       id=13   [slave  keyboard (3)]
    ↳ Eee PC WMI hotkeys                        id=15   [slave  keyboard (3)]
    ↳ EST Gaming keyboard                       id=16   [slave  keyboard (3)]

$ xev
KeyPress event, serial 37, synthetic NO, window 0x7c00001,
    root 0x4e5, subw 0x0, time 188722500, (165,-16), root:(4636,676),
    state 0x10, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"
    XmbLookupString gives 1 bytes: (61) "a"
    XFilterEvent returns: False

KeyRelease event, serial 37, synthetic NO, window 0x7c00001,
    root 0x4e5, subw 0x0, time 188722576, (165,-16), root:(4636,676),
    state 0x10, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"
    XFilterEvent returns: False

In trying to implement the suggestion by @Raffa, I used "3" for the keyboard ID and I left the keycode as 38. However, the key still duplicates.


Try this in a bash script file:

#!/bin/bash

xinput test 11 |

while read pkc
do
   if [[ "$pkc" =~ "key press   38" ]]
   then
        xmodmap -e 'keycode 38 = ';
        sleep 0.5;
        xmodmap -e 'keycode 38 = a A';
   fi
done
  • Change the number 11 in xinput test 11 to your keyboard device number. You can find this number by running xinput list. You might need to check if the id number is the right one for your keyboard. To do that choose the keyboard id numbers with slave keyboard in-front of them then check the id in the terminal by running xinput test id_number and press the a on your keyboard. If you get an output like key press 38 then this is the correct id number for your current keyboard and if no output, continue testing the other id numbers until you see output.

  • Change the nuber 38 in "key press 38" and xmodmap -e 'keycode 38 = '; and xmodmap -e 'keycode 38 = a A'; to the key code of the a key. You can find this number by running xev and pressing the a key.

  • Change the number 0.5 in sleep 0.5; to the desired period in seconds for the a key to be disabled.


Steps to creating and using the script file:

  1. Create and open the file in an editor by running the following command in the terminal:
nano ~/no_aa.sh
  1. Copy and paste the above code ( after modifying it ) into the editor.

  2. Save the script file and exit the editor by pressing Ctrl + X then press Y.

  3. Make the script file executable by running the following command in the terminal:

chmod +x ~/no_aa.sh
  1. Run the script by running the following command in the terminal:
bash ~/no_aa.sh
  1. Keep the terminal open and test the a key in other applications like writing in the LibreOffice writer.