-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsleep_cls.hpp
More file actions
68 lines (61 loc) · 1.09 KB
/
sleep_cls.hpp
File metadata and controls
68 lines (61 loc) · 1.09 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once
#ifdef _WIN32
#include <windows.h>
#include <conio.h>
#else
#include <unistd.h>
#include <stdio.h>
#include <termios.h>
#endif
#ifdef _WIN32
const int _back_ = 0x08;
const int _del_ = 0x2e;
const int _enter_ = 0x0d;
const int _directon_ = 0xe0;
const int _left_ = 0x4b;
const int _rigth_ = 0x4d;
#else
const int _back_ = 127;
const int _del_ = 27;
const int _enter_ = 10;
const int _directon_ = 27;
const int _left_ = 67;
const int _rigth_ = 68;
#endif
class MySleepCls
{
public:
void my_sleep(unsigned int ms)
{
#ifdef _WIN32
Sleep(ms);
#else
usleep(ms * 1000);
#endif
}
void my_cls()
{
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
int my_getch()
{
#ifdef _WIN32
return _getch();
#else
struct termios oldt,
newt;
int ch;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
return ch;
#endif
}
};