title: Linux shell: poll the keyboard button's state
body: <p>I have a script that is executed periodically in the background.
  I want to prevent its execution if the <kbd>Shift</kbd> key is pressed.</p>
  
  <p>The idea is to poll the keyboard's <kbd>Shift</kbd> button state, and if it's pressed — terminate the script immediately.</p>
  
  <p>Any ideas?  X server is allowed to use: I guess it will help.</p>
  
  <p><b>UPD:</b> I'm currently using this stupid hack:</p>
  
  <pre><code>[ $( sh -c 'cat /dev/input/by-id/usb-*kbd &amp; sleep 0.5 ; kill $! 2&gt;/dev/null' | wc -c ) -gt 1 ] &amp;&amp; exit 
  </code></pre>
  
  <p>The script just detects current keyboard events but does not distinguish them. 0.5sec is the kbd-events watch period. Not very nice, but still works :) </p>