Searching \ for '[OT]Kbhit' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=kbhit
Search entire site for: 'Kbhit'.

Exact match. Not showing close matches.
PICList Thread
'[OT]Kbhit'
2005\10\08@154506 by Dennis Crawley

flavicon
face

Hi all,
I wonder if this code works under WinNT and W2K.

#include <stdio.h>
#include <stdlib.h>

void main(void)
{
   float n=0;

   while (!kbhit()) {
       printf("\r%3.0f",n++);
     }
       printf("\n");


 system("PAUSE");
 return 0;
}

I already know that it works under XP, with out "compatibility mode on" for
this application.
Thank you in advance.

Dennis Crawley
Argnetina


       

       
               
___________________________________________________________
1GB gratis, Antivirus y Antispam
Correo Yahoo!, el mejor correo web del mundo
http://correo.yahoo.com.ar

2005\10\08@162543 by Andy Armstrong

flavicon
face
On 8 Oct 2005, at 20:43, Dennis Crawley wrote:
> I already know that it works under XP, with out "compatibility mode  
> on" for
> this application.

I'm not in a position to test it but I think kbhit() has been  
supported by Microsoft C compilers for years - from memory back to  
the 16 bit versions.

--
Andy Armstrong, hexten.net

2005\10\08@174818 by Dennis Crawley

flavicon
face
Andy, thanks to answer.

I'm changing old code in favor to WinAPIs.
I'm taking a "C" course and the professor doesn’t like my UART routines
because they "touch" the hardware directly. :)
For example, we have to use:
 CreateFile, WriteFile, ReadFile
 from windows.h

instead off:
 inp or outp form conio.h :)

They say is in favor of portability (I assume MS portability and something
to do with permissions), anyway I'm learning a lot. But I got stuck in a
terminal program. I hope I can use kbhit. Forgot to mention this is a
console32 application.


Dennis Crawley
Argentina

Andy Armstrong <spam_OUTandyTakeThisOuTspamhexten.net> wrote:
{Quote hidden}

               
___________________________________________________________ 1GB gratis, Antivirus y Antispam Correo Yahoo!, el mejor correo web del mundo http://correo.yahoo.com.ar

2005\10\08@175347 by olin piclist

face picon face
Dennis Crawley wrote:
> I wonder if this code works under WinNT and W2K.

How is anyone supposed to tell you without a definition of "works"?

*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

2005\10\08@180218 by Andy Armstrong

flavicon
face
On 8 Oct 2005, at 22:45, Dennis Crawley wrote:I'm changing old code  in favor to WinAPIs.
> I'm taking a "C" course and the professor doesn’t like my UART  
> routines
> because they "touch" the hardware directly. :)
> For example, we have to use:
>   CreateFile, WriteFile, ReadFile
>   from windows.h

That's fair enough - direct access to hardware devices won't work in  any operating system that makes a distinction between user mode code  and kernel mode code - generally speaking only kernel code will be  able to touch the hardware directly. Direct hardware access will also  mean your program would fail with, for example, a USB to serial  converter instead of a real serial port.

> They say is in favor of portability (I assume MS portability and  
> something
> to do with permissions), anyway I'm learning a lot. But I got stuck  
> in a
> terminal program. I hope I can use kbhit. Forgot to mention this is a
> console32 application.

I'm not 100% certain about the history of kbhit() but it was there in  the DOS days and if it's still there for XP I think it's reasonable  to assume it's been there through all the intermediate operating  systems - it's not the kind of function they'd re-introduce just for XP.

I've just had a quick Google. I think this page is useful:
 http://lyxus.net/rw

Unfortunately it doesn't display in Safari (nice one MS :) but from  what I can see in Google's synopsis it implies that kbhit() has  always been available but that they're now deprecating it in favour  of _kbhit() (with an underscore).

-- Andy Armstrong, hexten.net

2005\10\08@181013 by Spehro Pefhany

picon face
At 04:43 PM 10/8/2005 -0300, you wrote:

>Hi all,
>I wonder if this code works under WinNT and W2K.

Compiling it as a C console application under Dev-C++
Win2K yields the expected results.

>Best regards,

Spehro Pefhany --"it's the network..."            "The Journey is the reward"
.....speffKILLspamspam@spam@interlog.com             Info for manufacturers: http://www.trexon.com
Embedded software/hardware/analog  Info for designers:  http://www.speff.com
->> Inexpensive test equipment & parts http://search.ebay.com/_W0QQsassZspeff


2005\10\08@183059 by Dennis Crawley

flavicon
face

Well Olin,
if you try to run an application with inp and outp, trying to set or reset
UART bits directly, probably, your Win98 is happy with that. (Do I have to
define "happy"?). But in the moment you run this application under NT or W2K
environment, the OS, warns you with a lot of message boxes, as well as in XP
environment.

This concept is the opposite concept of works, but you are smart, and you
can figure out in which way "works" is used to denote "..with-out annoying
messages", or more appropriate, with a legal use of the OS.

I don't know if the use of Kbhit is "legal" to NT and W2K, or should I have
to learn another method to see keyboard events from APIs.




Olin Lathrop <olin_piclistspamKILLspamembedinc.com> wrote:
{Quote hidden}

               
___________________________________________________________
1GB gratis, Antivirus y Antispam
Correo Yahoo!, el mejor correo web del mundo
http://correo.yahoo.com.ar

2005\10\08@183735 by Dennis Crawley

flavicon
face
Thank you for this informaton Spehro,
I use Dev-C++ too.
Regards,
Dennis.


Spehro Pefhany wrote:
> At 04:43 PM 10/8/2005 -0300, you wrote:
> Compiling it as a C console application under Dev-C++
> Win2K yields the expected results.
>> Best regards,



       

       
               
___________________________________________________________
1GB gratis, Antivirus y Antispam
Correo Yahoo!, el mejor correo web del mundo
http://correo.yahoo.com.ar

2005\10\09@035627 by Xiaofan Chen

face picon face
With Visual C++ 2005 Express Edition Beta 2 (free download
from Microsoft), the attached code can be built.

Using kbhit() is also okay but the warning message says that
kbhit() is deprecated.

Regards,
Xiaofan

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int main(void)
{
   float n=0;

   while (!_kbhit()) {
       printf("\r%3.0f",n++);
     }
       printf("\n");


 system("PAUSE");
 return 0;
}

The following is the supplied example code for _kbhit().
// crt_kbhit.c
// compile with: /c
/* This program loops until the user
* presses a key. If _kbhit returns nonzero, a
* keystroke is waiting in the buffer. The program
* can call _getch or _getche to get the keystroke.
*/

#include <conio.h>
#include <stdio.h>

int main( void )
{
  /* Display message until key is pressed. */
  while( !_kbhit() )
     _cputs( "Hit me!! " );

  /* Use _getch to throw key away. */
  printf( "\nKey struck was '%c'\n", _getch() );
}


On 10/9/05, Dennis Crawley <.....proyectosenpicKILLspamspam.....yahoo.com.ar> wrote:
{Quote hidden}

> -

2005\10\09@040015 by Xiaofan Chen

face picon face
I forget to mention that the main function needs to be
defined as int main(void) since you have returned 0
in the end of the main() function. If not, there is another
warning message.

I think it should work across all the Visual C++ versions
since kbhit() or  _kbhit() is part of the C run-time library for quite
some time already (I remember Microsoft C version 5 has it).

Regards,
Xiaofan

2005\10\09@053014 by William Chops Westfield

face picon face
On Oct 8, 2005, at 3:29 PM, Dennis Crawley wrote:
>
> This concept is the opposite concept of works, but you are smart, and
> you
> can figure out in which way "works" is used to denote "..with-out
> annoying
> messages", or more appropriate, with a legal use of the OS.
>
I for one was wondering whether how you thought "working" was defined
when the window running that program didn't have the focus (wasn't
the active window.)

IMO, if this is for a class, you probably ought to figure out the proper
windows APIs to do what you had in mind (unless it's not a windows
programming class at all.)  Windows programming uses a rather different
methodology than DOS programming, even if many DOS programs will run OK
in a windows environment.  (OTOH, this makes the program MUCH more
complicated...)

BillW

2005\10\09@061048 by Andy Armstrong

flavicon
face
On 9 Oct 2005, at 10:30, William Chops Westfield wrote:
> I for one was wondering whether how you thought "working" was defined
> when the window running that program didn't have the focus (wasn't
> the active window.)
>
> IMO, if this is for a class, you probably ought to figure out the  
> proper
> windows APIs to do what you had in mind (unless it's not a windows
> programming class at all.)  Windows programming uses a rather  
> different
> methodology than DOS programming, even if many DOS programs will  
> run OK
> in a windows environment.  (OTOH, this makes the program MUCH more
> complicated...)

I think he said he's writing a command line tool in which case it  
appears from KB article I posted a link to that the approved function  
name is _kbhit() - but apart from that (and the warnings of course)  
he's doing the right thing.

--
Andy Armstrong, hexten.net

2005\10\09@112316 by Dennis Crawley

flavicon
face
...and that is what I was trying to do!, thanks to you and Andy, I will take
a look in MS site for further researchs.
Wow! It "works", in all "senses" of the word. (strictus et lato)

Best Regards,
Dennis Crawley
Argentina

Xiaofan Chen <EraseMExiaofancspam_OUTspamTakeThisOuTgmail.com> wrote:
{Quote hidden}

>> --

More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...