Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-29-2009, 04:02 AM   #1
LQ Newbie
Registered: Apr 2009
Posts: 5

Rep: Reputation: 0
ignoring keyboard buffer

The process in a script is as such

sleep 3
read x
I want all keys pressed while "sleep 3" was working not to appear
when the read command is executed. I want to ignore all keyboard actions while "sleep 3" is working.

Old 06-29-2009, 03:03 PM   #2
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Hello silverblimp

I think that is impossible to do precisely in shellscript. Keys pressed during the sleep go into a buffer. Even if it were possible to discard the buffer it would take some time, however little, and more keystrokes could arrive during that time. Abandon hope all ye who enter the messy world of asynchronous and non-atomic processes!

You may be able to approximate what you want to do by using a timed read with the -n1 option in a loop. This will read a single "character" (in quotes because it also gets non-characters such as arrow keys). If the time is short you could (imprecisely) assume the character was entered during the sleep. The first character that takes a longer time should be the first character entered after the sleep.

Not perfect but it may be "good enough" for what you want to do.




Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between the free buffer and buffer in the buffer hash queue? Swagata Linux - Enterprise 0 05-26-2006 12:57 AM
how to write to keyboard buffer vineeth789 Programming 1 01-11-2006 04:30 PM
Wine ignoring keyboard elvee Linux - Games 10 09-13-2004 07:03 AM
Send data to the keyboard buffer rrodrigues Programming 5 07-20-2004 10:26 AM
Keyboard output buffer Majestros Linux - Hardware 0 07-06-2004 10:01 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:14 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration