Archived

This topic is now archived and is closed to further replies.

FrancoisSoft

Windows API Console Programming

Recommended Posts

Hi everybody, I''ve just been contemplating how to make my own DOS system which I will call MicroDOS in order to experiment with various techiques that are low level. I''m working under windows so I''m using the console functions of the Windows API. I''ve been practicing on how to read keystrokes from consoles using ReadConsoleInput(). In case you want to know I did not create a screen buffer but rather I obtained the handles to the standard input/output. I ran into trouble reading one character at a time in a continuous loop. Here''s what I mean... char Key; INPUT_RECORD IR[1]; HANDLE In; HANDLE Out; char OutBuff[10]; In = GetStdHandle(STD_HANDLE_INPUT); Out = GetStdHandle(STD_HANDLE_OUTPUT); while(Key != ''q'') { ReadConsoleInput(In, IR, 1, NULL, NULL); if (IR[0].Event == KEY_EVENT) { if (IR[0].Event.KeyEvent.KeyDown) { Key = IR[0].Event.KeyEvent.uChar.AsciiChar; OutBuff[0] = Key; WriteConsole(Out, OutBuff, 10, NULL, NULL); } } } Ok, see what I''m doing? The problem I''m having is that I''m not getting much of a reponse in terms of key input. In other words a character should appear on the screen. What should I do? Hey, don''t forget to visit my page... by clicking here!

Share this post


Link to post
Share on other sites
Well.. there are many ways of doing this stuff.. but try this:



#include <iostream>
#include <conio.h>

void main()
{
int key;

while( key = getch() )
{
std::cout << (char)key;
}
}


of course, you have to check for Caps Lock and stuff... but this is a beginning! =)

----------------------------------------------
Petter Nordlander

"There are only 10 kinds of people in the world. Those who understand binary and those who don't"

[edited by - Magmai Kai Holmlor on August 13, 2003 11:51:00 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by PhiberOptic
Well.. there are many ways of doing this stuff.. but try this:



#include <iostream>
#include <conio.h>

void main()
{
int key;

while( key = getch() )
{
std::cout << (char)key;
}
}


of course, you have to check for Caps Lock and stuff... but this is a beginning! =)

----------------------------------------------
Petter Nordlander

"There are only 10 kinds of people in the world. The who understand binary and those who don''t"


No, that just isn''t gonna do it. The kind of keyboard input I want is smooth keyboard input just like the one that would be in a game or on a window.


Hey, don''t forget to visit my page... by clicking here!

Share this post


Link to post
Share on other sites