'nix equivalent of Dos function kbhit() ?

E

exquisitus

Hi all,

I'm porting a DOS application to run on Linux. I need to replace this
function or use an equivalent. Anyone knows how or where I can get this
function's equivalent (or maybe someones hacked an implementation that
works on Linux)?

look forward to your response

Tanks
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi all,

I'm porting a DOS application to run on Linux. I need to replace this
function or use an equivalent. Anyone knows how or where I can get this
function's equivalent (or maybe someones hacked an implementation that
works on Linux)?

look forward to your response

Sorry, but kbhit() isn't a C standard function, and this newsgroup can't help
you with replacing it.

<OT>
1) You'll have better luck in one of the comp.os.linux newsgroups. I'd suggest
comp.os.linux.development.apps
2) kbhit() can be emulated with a judicious use of termios() and ioctl() calls.
Neither termios() nor ioctl() are C standard functions, and should also be
discussed elsewhere.
3) If you are trying to use kbhit(), then you are trying to solve the wrong
problem. Find a way to code your program so that it is device independant, and
does not need to know when a key has been pressed. Many systems do not have
'keys' to be hit, and most applications should be runnable entirely from files.
kbhit() or workalikes restrict your program to interactive use in a keyboarded
environment, or worse, and should be avoided.
</OT>


- --
Lew Pitcher
IT Specialist, Enterprise Data Systems,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFCWsiKagVFX4UWr64RAkMbAKDaX1auC97O9ERsek0FE53ebPsFRACg0k32
Y7Rg0j9cZyUWjhgmM3t0UAs=
=S365
-----END PGP SIGNATURE-----
 
K

Keith Thompson

Lew Pitcher said:
Sorry, but kbhit() isn't a C standard function, and this newsgroup
can't help you with replacing it.
Agreed.
[snip]
3) If you are trying to use kbhit(), then you are trying to solve
the wrong problem. Find a way to code your program so that it is
device independant, and does not need to know when a key has been
pressed. Many systems do not have 'keys' to be hit, and most
applications should be runnable entirely from files. kbhit() or
workalikes restrict your program to interactive use in a keyboarded
environment, or worse, and should be avoided.
</OT>

If my text editor waited for me hit <return> before processing any
input, and stopped accepting input when I hit control-D (or whatever
mechanism the system uses to denote EOF), I'd be very unhappy.

*Unnecessary* device dependence should be avoided, but device
dependence is sometimes necessary, or at least useful enough to be
worthwhile.
 
D

Dan P.

Lew Pitcher said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Sorry, but kbhit() isn't a C standard function, and this newsgroup can't
help
you with replacing it.

<OT>
1) You'll have better luck in one of the comp.os.linux newsgroups. I'd
suggest
comp.os.linux.development.apps
2) kbhit() can be emulated with a judicious use of termios() and ioctl()
calls.
Neither termios() nor ioctl() are C standard functions, and should also be
discussed elsewhere.
3) If you are trying to use kbhit(), then you are trying to solve the
wrong
problem. Find a way to code your program so that it is device independant,
and
does not need to know when a key has been pressed. Many systems do not
have
'keys' to be hit, and most applications should be runnable entirely from
files.
kbhit() or workalikes restrict your program to interactive use in a
keyboarded
environment, or worse, and should be avoided.
</OT>


Functions like kbhit() sometimes cannot be avoided. I just worked on a DOS
application where the requirements specifically said that they should be
able to press any key to interrupt a continuous data acquisition routine. I
can't think of any way to program this in Standard C. The input routines
defined in stdio.h would all stop the program and wait for input. This is
impossible in this program because it has to be constantly acquiring data.
Any missed data (while waiting for user input) would be very bad.

This really goes for all platform-specific extensions to the language.
Whether your program can be 100% portable depends on your customer's
requirements. Standard C is very limiting and for alot of applications out
in the real world today, it'll be impossible to create a 100% portable
application.


Dan
 
L

Lawrence Kirby

Lew Pitcher said:
Sorry, but kbhit() isn't a C standard function, and this newsgroup
can't help you with replacing it.
Agreed.
[snip]
3) If you are trying to use kbhit(), then you are trying to solve
the wrong problem. Find a way to code your program so that it is
device independant, and does not need to know when a key has been
pressed. Many systems do not have 'keys' to be hit, and most
applications should be runnable entirely from files. kbhit() or
workalikes restrict your program to interactive use in a keyboarded
environment, or worse, and should be avoided.
</OT>

If my text editor waited for me hit <return> before processing any
input, and stopped accepting input when I hit control-D (or whatever
mechanism the system uses to denote EOF), I'd be very unhappy.

There is nothing in C's input stream mechanism that requires it to wait
*Unnecessary* device dependence should be avoided, but device
dependence is sometimes necessary, or at least useful enough to be
worthwhile.

True, and here device dependency can often be limited to initially
detecting the device type and setting it to a "raw" state. From that point
on the same code can be used with input from keyboards, files,
pipes, network connections etc.

Lawrence
 
D

Darius

exquisitus said:
Hi all,

I'm porting a DOS application to run on Linux. I need to replace this
function or use an equivalent. Anyone knows how or where I can get this
function's equivalent (or maybe someones hacked an implementation that
works on Linux)?

look forward to your response

Tanks

i don't remember the exact way to implement it, but you can find the
implementation in "Beginning linux programming, by WROX publication".
 
C

Chris Croughton

If my text editor waited for me hit <return> before processing any
input, and stopped accepting input when I hit control-D (or whatever
mechanism the system uses to denote EOF), I'd be very unhappy.

You mean you're /not/ using ed or em? said:
*Unnecessary* device dependence should be avoided, but device
dependence is sometimes necessary, or at least useful enough to be
worthwhile.

Essential, in the area I work (embedded systems). OK, we try to
encapsulate the device dependence in a few modules, but it wouldn't work
without it...

Chris C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top