2

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.

2
  • you..could just get a new keyboard instead
    – Wboy
    Jun 29, 2021 at 12:32
  • The obvious reason to go through this trouble is because the keyboard I had at the time was not inexpensive to replace. I did eventually need to replace it though as no solution actually solved the problem completely.
    – Jdclark
    Jun 30, 2021 at 13:33

1 Answer 1

3

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.
9
  • I tried this and doesn't seem to work. The "a" key keeps duplicating and it still registers keypresses that that I know are within the sleep interval. For example, if I set it to sleep for 3 seconds, I can still type the letter "a" multiple times within three 3 seconds. Should I have executed any of these commands as root? (Also, I don't get any errors when I run the script)
    – Jdclark
    Apr 23, 2020 at 20:37
  • Another possibility is that I'm using the wrong Keyboard ID. When I run 'xinput list' I have like 7 "keyboards" in the list.
    – Jdclark
    Apr 23, 2020 at 20:38
  • @Jdclark Did you run xinput list and xev and changed the numbers? Please add the output of those commands to your question and indicate what numbers you used.
    – Raffa
    Apr 23, 2020 at 20:41
  • Run xinput test 3 in the terminal and press the a key. If no output in the terminal like key press 38 then change the keyboard device number after xinput test to the other keyboard device numbers in your post like xinput test 8 and test it again in the terminal untill you get output then use that number in the script
    – Raffa
    Apr 23, 2020 at 20:56
  • 1
    It worked! It looks like "13" was the correct number. Will this continue to work if I plug the keyboard into a different the USB port? Also, will the same ID numbers be used after a reboot?
    – Jdclark
    Apr 23, 2020 at 21:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .