Skip to main content
GameDev.net gamedev.net
🔒 Locked

Text programmers?

Started by Zao Nov 30, 2001 at 6:31 PM 0 replies 350+ views
Original Post
Zao
Zao
Does anyone have any idea how to make a program that prints out what you press on the keyboard. I have been trying but failing. I have been using the WM_CHAR command combined with a for loop to get it to work but it refuses to give me success.
To make it is hell. To fail is divine.
SHilbert
SHilbert
There are several ways to do this. The simplest would be this (compiled as a console app in MSVC):

    
#include <stdio.h>

#include <conio.h>

int main(int argc, char**argv)
{
while(1)
{
char c = getch();
if(c == 27)
break;
else
printf("%c", c);
}
return 0;
}


That code should basically keeps reading in characters from the keyboard until you hit ESCAPE, and prints them out in the console.

However, given your reference to WM_CHAR I think you might be wanting to do this as a Win32 app, not a console one. This is a little more difficult to pseudocode. Basically, you want to set up a normal window (there are countless tutorials on the web about this; you can also make a basic "hello world!" app in MSVC with a few clicks of the mouse.) Once you've done that you want to respond to the WM_CHAR message by somehow displaying the wParam associated with that message. If you need more help with this I could write some real code for you

PS, You might have to be more specific in the future to get more specific help. WM_CHAR isn't exactly a command and I don't see where a for loop fits in, so it's a little difficult to understand what you're asking for, but I try

If life was like Counter-Strike...

Edited by - SHilbert on November 30, 2001 12:06:22 AM

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.