Newsgroup: comp.unix.programmer


Date: Sun, 30 Apr 2006 17:49:24 +0300
From: Diomidis Spinellis <dds@aueb.gr>
Organization: Athens University of Economics and Business
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.2) Gecko/20060404 SeaMonkey/1.0.1
MIME-Version: 1.0
Newsgroups: comp.unix.programmer
Subject: Re: How to force keystrokes into the buffer on Unix
References: <e30i3r$huf$1@news.xmission.com> <barmar-9EAB5E.00314530042006@comcast.dca.giganews.com> <e31gos$7fn$1@news.xmission.com>
In-Reply-To: <e31gos$7fn$1@news.xmission.com>
Content-Type: text/plain; charset=ISO-8859-7; format=flowed
Content-Transfer-Encoding: 7bit
Kenny McCormack wrote:
> In article <barmar-9EAB5E.00314530042006@comcast.dca.giganews.com>,
> Barry Margolin  <barmar@alum.mit.edu> wrote:
>> In article <e30i3r$huf$1@news.xmission.com>,
>> gazelle@xmission.xmission.com (Kenny McCormack) wrote:
>>
>>> I know there is a way to do this - that is, a system call that allows
>>> you to push a character into the keyboard buffer - but I can't seem to
>>> find it now (checked man pages for tty, termio(s) on several systems).
>>>
>>> I found a workaround, with expect, like this:
>>>
>>> 	expect -c 'spawn program;expect something;send key;interact'
>>>
>>> but I'd prefer to avoid that as it brings in the overhead of expect and
>>> a tty layer just to push one key.  Anyway, I think I did this a long
>>> time ago and that it is TIOsomething.  Can anyone help?
>> I think you're thinking of TIOCSTI -- I believe STI stands for Store 
>> Terminal Input.
> 
> That sounds right.  Could you tell me where to find the documentation
> for it on a Linux system?  I thought it would be in "man 4 tty", but it
> doesn't seem to be.

Grep is your friend for locating function and macro definitions.  To 
find the include file where TIOCSTI is defined run something like:

grep TIOCSTI /usr/include/**/*.h

On a Linux box I have access to the above command returns:

/usr/include/asm-i386/ioctls.h:#define TIOCSTI          0x5412
/usr/include/asm-x86_64/ioctls.h:#define TIOCSTI                0x5412
/usr/include/linux/compat_ioctl.h:COMPATIBLE_IOCTL(TIOCSTI)

Similarly you can find the relevant manual page by running:

cd /usr/share/man/man2
for i in *; do (zcat $i | grep TIOCSTI) && echo $i; done

If the above fails (it didn't help me on the systems I tried it on), you 
can read the corresponding kernel source code, look at manual pages of 
other (hopefully better documented) systems, or Google for example code. 
  For TIOCSTI, see for 
http://www.developerweb.net/forum/archive/index.php/t-3799.html

-- 
Diomidis Spinellis
Code Quality: The Open Source Perspective (Addison-Wesley 2006)
http://www.spinellis.gr/codequality?cup



Newsgroup comp.unix.programmer contents
Newsgroup list
Diomidis Spinellis home page

Creative Commons License Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-Share Alike 3.0 Greece License.