WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

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.

Zvjezdan23 -13 Junior Poster

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

Zvjezdan23 -13 Junior Poster

@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

senusret_V 0 Newbie Poster

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. :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

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.

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

    return 0;   
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.