how to detect key presses

I am making a REAL program, named shUI. It is a shell program
designed to help those whose computer isn't strong enough to
support the X window system.
I'm stuck here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
int main(){
int frm1();
frm1();
};
void frm1(){
cout << " ________________________\n";
cout << "|   \\_____Setup______/   |\n";
cout << "| ______________________ |\n";
cout << "||  Welcome to shUI's   ||\n";
cout << "||installation program! ||\n";
cout << "||                      ||\n";
cout << "||                      ||\n";
cout << "||                      ||\n";
cout << "||______________________||\n";
cout << "| <Quit |        | Next> |\n";
cout << "`------------------------'";
cout << "";
}

I want to move through the installation with the direction keys.
It's not possible using standard C++. You will have to use system calls or use a library like ncurses.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <fstream>
#include <conio.h>
using namespace std;

const unsigned char Key1 = 224;
const unsigned char LEFT = 75;
const unsigned char RIGHT = 77;
const unsigned char UP = 72;
const unsigned char DOWN = 80;


int main(){
int frm1();
frm1();
};
void frm1(){
cout << " ________________________\n";
cout << "|   \\_____Setup______/   |\n";
cout << "| ______________________ |\n";
cout << "||  Welcome to shUI's   ||\n";
cout << "||installation program! ||\n";
cout << "||                      ||\n";
cout << "||                      ||\n";
cout << "||                      ||\n";
cout << "||______________________||\n";
cout << "| <Quit |        | Next> |\n";
cout << "`------------------------'";
cout << "";

unsigned char choice = getch();
cout << endl;
if (choice == Key1)
    {
        unsigned char choice2 = getch();
        switch(choice2)
        {
            case LEFT:
                cout << "You Pressed Left ";
                break;
            case RIGHT:
                cout << "You Pressed Right";
                break;
            case UP:
                cout << "You Pressed Up";
                break;
            case DOWN:
                cout << "You Pressed Down";
                break;
        }
    }

return ;

}
I doubt the maxum wants to use conio.

I can recommend ncurses.
I need to ask you the following things:
1. How to make cout (or a variant of it) scroll horizontally if the text exceeds the determined limit?
2. How to set where cout will print on the screen
Last edited on
Topic archived. No new replies allowed.