Getting key strokes in c

Started by nima, March 28, 2011, 08:16:33 PM

Previous topic - Next topic

nima

hi,
I'm trying to make a game and i need to get keystrokes. I cannot use getchar() because it needs an enter after the character is typed.

Vortex

You need to process the WM_CHAR message to read keyboard input.
Code it... That's all...

TimoVJL

if you use console, try _getch(), include conio.h
May the source be with you

nima

Thanks timovjl, _getch() works as I wanted,
but it returns 224 for all of the arrow keys. I can use other keys but is there a way to use arrows.

CommonTater

Quote from: nima on March 28, 2011, 10:09:41 PM
Thanks timovjl, _getch() works as I wanted,
but it returns 224 for all of the arrow keys. I can use other keys but is there a way to use arrows.

Some keys return two characters... so you need to check the first to see if it's an "arrow key" then deal with the second character to find out which one it is...

Something to the effect of ... if (first key == 224 ) get second key...

nima

Thanks a lot CommonTater.
Problem solved  :)

abhas

i am just curious- how to get the second key?

CommonTater

#7
Quote from: abhas on April 09, 2011, 05:00:24 AM
i am just curious- how to get the second key?

Call getchar() again.


if (key == 224)
  key = GetChar();


It might be a bit more complex than that, I don't recall offhand if the second character value overlapps the regular key values... but a bit of experimentation will give you the answer.


abhas