0

I have a broken key on my keyboard, The dot "." to be specific. It behaves very oddly, about 7/10 times the keyboard types a double dot ".." when clicked once. I use xbindkeys to intercept when the dot key is pressed and trigger my bash script to start. The bash script I wrote checks how many instances of it are running and only types the "." once.

  #!/bin/bash
  let "target=2"
  curr=$(ps -A | grep 'dot-writer.sh' | wc -l)
  if [ "$curr" -eq "$target" ]
  then
    numlockx on
    xdotool key KP_Delete
    sleep 0.1
  fi

As you can see from the script I am not actually typing the "." key with xdotool, but instead, I am enabling Numlock and typing the other"." on my keyboard located on the keypad on the same button as delete.

As you can probably guess this is not a perfect solution because those two keys do not exactly act the exact same way 100% of the time.

I tried telling xdotool to type the "." as a Unicode character

xdotool key U002E

I tried telling xdotool to type the "." as a string generated by Bash

xdotool type $'.'

I tried telling xdotool to type the "." as a string generated by Bash containing the Unicode character "."

xdotool type $'\u002E'

None of this seems to work as it get intercepted as if the dot key has been pressed by xbindkeys and triggers the same script again and again.

Is there anything I can do? Can I use some other tool to imitate a key press?

Egene
  • 183
  • 1
  • 7

1 Answers1

2

You can try copying the dot to your primary clipboard so you can paste it instead of sending the key. A variable is used to save and restore previous contents of the clipboard.

contents=$(xclip -selection primary -o)

echo -n "." | xclip -selection primary
xdotool key --clearmodifiers Shift+Insert

echo -n "$contents" | xclip -selection primary
fzbd
  • 477
  • 2
  • 8
  • Sounds like an idea, but isn't this solution even less reasonable? What if I have other stuff copied and do not want it to be lost if I press the doy key? – Egene May 16 '17 at 17:00
  • thanks I will try that out when i get back to my computer and if it works will upvote your answer – Egene May 17 '17 at 13:25