H
H
HentaiEtoIskusstvo2017-08-02 11:40:22
Programming
HentaiEtoIskusstvo, 2017-08-02 11:40:22

What functions (or non-functions) should be used to create a moving object in the console on pressing a certain key?

Let's say I have a char variable. I want to make it so that when I press, for example, the "W" key, my character moves up, when I press "S" - down, etc.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LexArd, 2017-08-02
@HentaiEtoIskusstvo

if on Windows, then the simplest:

#include <conio.h>
....
char key = getch();
switch(key) {
case 's': direction = DOWN;
              break;
}

L
Legebocker, 2017-08-04
@EnDeRJaY

charm;
char m=getch();
switch(m)
{case "W":Example1();break;
case "S":Example2();break;
default:break;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question