digitalmars.D.learn - D and windows console kbhit, getch etc
- Jason King (22/22) Jun 02 2012 I've seen a few messages asking how to get this to work and the
- Danny Arends (3/25) Jun 04 2012 Wow been looking for this for some time,
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.
Jun 02 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.
Jun 04 2012








"Danny Arends" <Danny.Arends gmail.com>