LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: 0
ignoring keyboard buffer


The process in a script is as such

Code:
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.

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

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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.

Best

Charles
 
  


Reply



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-25-2006 11:57 PM
how to write to keyboard buffer vineeth789 Programming 1 01-11-2006 03:30 PM
Wine ignoring keyboard elvee Linux - Games 10 09-13-2004 06:03 AM
Send data to the keyboard buffer rrodrigues Programming 5 07-20-2004 09:26 AM
Keyboard output buffer Majestros Linux - Hardware 0 07-06-2004 09:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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