Advertisement

getch in win32 app

Started by July 30, 2000 04:19 AM
4 comments, last by POINT 24 years, 4 months ago
does getch function correctly in a win32 app? if not is there a win32 function that does the same (or similar) thing? i need to get text input from the user in a game im working on and scanning through VK_ values get''s tedious.
The letters A-Z in VK_ codes are the same as ASCII ''A'' to ''Z''. You can check if button the user pressed is between those values, and if so, add it to the inputted string.

- Daniel
VG Games
- DanielMy homepage
Advertisement
yea, but i also want the rest of the keys (ie .,><>/?!"£$%^&*()_+[]{}@''~# etc...)

the good thing about getch() was that it returned an ascii value, you didnt have to know any values:

mystring += getch();

but using getkeystate:

for(int i=''A''; i<=''Z''; ++i)
{
if(GetKeyState(i) & 0x80) mystring += static_cast(i);
}

the latter method is worse because it only works with letters (and in uppercase - you also need to manually check for shift key etc.). To add support for numbers, it''s another for loop.
it''s just a pain.
Oh? U want something like u could read on DOS?
Okay enough of the cheasy act : )

WM_CHAR message is sent to a window when a key is pressed.
The character is TCHAR I believe. You can use it like a
CHAR : )
such as "Esc" = 27 and "Return/Enter" = 13

Hope that gives u some help.
-John (x3r0@x3r0.com)
X E R O D E V E L O P M E N T
WWW.X3R0.COM
X E R O-D E V E L O P M E N THTTP://WWW.X3R0.COM
x3r0:
thanks - that did it
As an alternative, you can just use GetKeyState (which is faster than waiting for the message loop). Just use it like so:

if ( HIWORD( GetKeyState(VK_ESCAPE) ) )
{
//do stuff here
}

Note that there are no VK codes for A-Z, though, so you would have to use the number 65 for A, for example.

----------------------------------------
Whenever I see an old lady slip and fall on a wet sidewalk, my first instinct is to laugh. But then I think, what if I was an ant and she fell on me? Then it wouldn't seem quite so funny.

This topic is closed to new replies.

Advertisement