473,320 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

'nix equivalent of Dos function kbhit() ?

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

Nov 14 '05 #1
6 2761
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

exquisitus wrote:
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)

iD8DBQFCWsiKagVFX4UWr64RAkMbAKDaX1auC97O9ERsek0FE5 3ebPsFRACg0k32
Y7Rg0j9cZyUWjhgmM3t0UAs=
=S365
-----END PGP SIGNATURE-----
Nov 14 '05 #2
Lew Pitcher <Le*********@td.com> writes:
[...]
Sorry, but kbhit() isn't a C standard function, and this newsgroup
can't help you with replacing it.
Agreed.
<OT> [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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #3
On Mon, 11 Apr 2005 22:07:50 +0000, Keith Thompson wrote:
Lew Pitcher <Le*********@td.com> writes:
[...]
Sorry, but kbhit() isn't a C standard function, and this newsgroup
can't help you with replacing it.
Agreed.
<OT>

[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
for <return> or treat control-D in any special way. Streams can be and are
used to implement interactive programs inclusing text editors.
*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

Nov 14 '05 #4

"Lew Pitcher" <Le*********@td.com> wrote in message
news:8S*******************@news20.bellglobal.com.. .
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

exquisitus wrote:
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>

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

Nov 14 '05 #5

exquisitus wrote:
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".

Nov 14 '05 #6
On Mon, 11 Apr 2005 22:07:50 GMT, Keith Thompson
<ks***@mib.org> wrote:
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? <g>
*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
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: dbrown2 | last post by:
I'm having some trouble using kbhit inside the editor enviroments. I'm using win2000 with Python2.3 and win32all v157 versions. Any pointer on how this should be handled would be appreciated. Is...
4
by: Radioactive Man | last post by:
anyone know of a function like "raw_input", which collects a string from the user entry, but one where I can set a time limit, as follows: time_limit = 10 # seconds user_answer =...
1
by: Hans Georg Krauthaeuser | last post by:
Hey all, this is probably a FAQ, but I didn't found the answer... I use msvcrt.kbhit() to check for a user keyboard event on windows. But now, I would prefer to make the module independent...
2
by: Gnurp Gnarp | last post by:
How do I prevent the MySQL client to scroll pages when the results of a query exceeds the number of lines in the terminal window? Like a MySQL equivalent to *nix 'more'. mysql> select foo from...
4
by: groleo | last post by:
Hi. I'm trying to port a piece of code, written for win32, that uses the finddata_t structure. Is there an equivalent , or a work-around, that implement finddata_t on *nix platforms?
1
by: Lakshan | last post by:
Hi, How do you emulate a key board hit in C# without actually reading in the character. For instance I have the following code Console.WriteLine("Press a enter to exit"); Console.ReadLine();...
1
by: Carsten Orthbandt | last post by:
This code: ---snip--- #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include <stdio.h> #include <tchar.h> #include <conio.h> int _tmain(int argc, _TCHAR*...
1
by: pavanponnapalli | last post by:
hi , Is there any function in perl like kbhit() in c programming? once a key in a keyboard is pressed, the control should come out of the loop. cheers, pavan
1
by: SpecialKay | last post by:
hey guys, i have a threaded program, i have loop that contunes until i get a kbhit() then, i playback repetively untill i get another kbhit(). EDIT: the first kbhit happens on a child thread of...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.