Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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?

share|improve this question
up vote 2 down vote accepted

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).

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.