4

I would like to detect if a key is being pressed when running a script. I have the following script:

#!/bin/bash
sleep 0.5
xte 'str sometext'

I run this script using a shortcut to paste "sometext" where I'm at in kde. I used a sleep 0.5 here because the script itself is run with a shortcut that uses ctrl and alt. If the sleep 0.5 is omitted, the result is that ctrl+s, ctrl+o, etc... is sent. I think the solution would be to add some bussy wait at the beginning that would block untill no keys are being pressed. How can I get this to work in the script?

AReddy
  • 3,122
  • 5
  • 35
  • 75
Silverrocker
  • 1,815
  • 1
  • 15
  • 23

1 Answers1

2

Since you are using xte anyways, why not release the keys with xte? Something along the lines

xte "keyup Control_L"
xte "keyup l"

(assuming your shortcut is ctrl-l).

January
  • 1,877
  • 2
  • 16
  • 14
  • ok this works for the alt key and control key, the only problem is that I have my capslock be another control key so the keyup on the control leaves the capslock down. I have searched for a way to keyup capslock but this seems not to be possible with xte. any suggestions? – Silverrocker Oct 15 '12 at 21:01