D and windows console kbhit, getch etc

Danny Arends Danny.Arends at gmail.com
Mon Jun 4 00:18:02 PDT 2012


Wow been looking for this for some time,
just tested it and it works on windowsXP 32 bit as well

On Sunday, 3 June 2012 at 02:55:53 UTC, Jason King wrote:
> I've seen a few messages asking how to get this to work and the 
> replies that were functional involved snagging the console 
> input handle and trolling for keyboard events yourself.  Since 
> that code is inside the standard library (at least for DMD) I 
> figured out the proper mix to make it work.
>
> import std.c.stdio;  // I'm just using this for the printf
> extern (C) void _STI_conio(); // initializes DM access ton 
> conin, conout
> extern (C) void _STD_conio(); // properly closes handles
> extern (C) int kbhit();       // the conio function is in the 
> DMD library
> extern (C) int getch();       // as is his friend getch
> void main() {
>   int mychar;
>    _STI_conio();
>    while(!kbhit())
>    {}
>    mychar = getch();
>    printf("%c\n",mychar);
>    _STD_conio();
> }
>
> Works on DMD 2.059 Windows 7 64 bit.




More information about the Digitalmars-d-learn mailing list