Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 588047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:16:38+00:00 2026-05-13T15:16:38+00:00

I have a script that is executed periodically in the background. I want to

  • 0

I have a script that is executed periodically in the background.
I want to prevent its execution if the Shift key is pressed.

The idea is to poll the keyboard’s Shift button state, and if it’s pressed — terminate the script immediately.

Any ideas? X server is allowed to use: I guess it will help.

UPD: I’m currently using this stupid hack:

[ $( sh -c 'cat /dev/input/by-id/usb-*kbd & sleep 0.5 ; kill $! 2>/dev/null' | wc -c ) -gt 1 ] && exit 

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 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:16:38+00:00Added an answer on May 13, 2026 at 3:16 pm

    First off, you can monitor key up/down events, but as far as I know, there’s no way to tell if the key is currently pressed. If you’re OK with that, then…

    That implies that the thing listening for the key event has to be running in another thread. The shell script will have to spawn a program in the background that listens for key events and sends a signal to the parent script on keypress. You can use trap to respond to the signal by exiting gracefully.

    Check out KeyPress. It might give you a good start.

    You may also be able to monitor /dev/input/eventN. This perl module may help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script in app/vendors/shells which is executed periodically via cron. In that
I have PHP web script that have to be executed periodically, using web browser.
If I have a python script that is executed via a symlink, is there
I have CMS with a script that is executed for each file that is
I have a script that's written in perl, and executed as CGI. It works
I have a SQL script that is being executed in TOAD. Currently, I have
I have a shell script that I want to set uid bit. I set
I have a PHP script that needs to determine if it's been executed via
I have a script that gives an error when being executed: Msg 1505, Level
I have a python script that, once executed from command line, performs the needed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.