That code didn't work for me so I modified it. This code will work for any situation that someone needs to use the up arrow, down arrow, left arrow, and right arrow.

It will? Try it on any Linux Compiler. Try it on any non-Borland/Microsoft compiler. It won't work in most of these situations which means it doesn't work.

What are you talking about??? I only posted this for up down left right arrows. Can you please explain what you mean??

@waltp: My bad. I'm sorry. I'm new to programming so idk if there is any difference. I thought everything that's C, C++, C# is coded in visual studios

Hello i just signed up for this question. I noticed that it was an old post but I also am making a game application which is going to be a 2D soccer game. I need a KeyListener in C++ which will detect keystrokes immediately. For example, to move a radiobutton a little right when i press right arrow on keyboard. Is the code above can do it? I must detect key stroke immediately (not 1-console input and 2-press enter to continue kind of program) I would really appreciate if any of you can answer me. :)

It might, assuming you don't plan to port the program to another operating system and use a compiler that supports functions in conio.h. conio.h and its associated library are non-standard, which means not all compilers will support it. Too bad because conio.h contains several really useful functions, such as kbhit(). But you can replicate that by using win32 api console functions.

#include <stdio.h>
#include <conio.h>
int main()
    while (1)
        printf("%d\n", getch());

    return 0;