-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeystroke.cpp
More file actions
60 lines (46 loc) · 1.52 KB
/
Copy pathkeystroke.cpp
File metadata and controls
60 lines (46 loc) · 1.52 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
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <iostream>
// Function to set terminal attributes for macOS input handling
void setTerminalAttributes() {
struct termios termAttr;
tcgetattr(STDIN_FILENO, &termAttr);
termAttr.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &termAttr);
}
// Function to restore terminal attributes on macOS
void restoreTerminalAttributes() {
struct termios termAttr;
tcgetattr(STDIN_FILENO, &termAttr);
termAttr.c_lflag |= ICANON | ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &termAttr);
}
int main() {
// Set terminal attributes for macOS input handling
setTerminalAttributes();
std::cout << "Press 'Q' to quit the loop." << std::endl;
while (true) {
char input;
if (read(STDIN_FILENO, &input, 1) != -1) {
if (input == 'q' || input == 'Q') {
break;
}
else if (input == 'p' || input == 'P') { // <-- Missing semicolon here
std::cout << "Paused! press c to continue." << std::endl;
while (true) {
if (read(STDIN_FILENO, &input, 1) != -1) {
if (input == 'c' || input == 'C') {
break;
}
}
}
}
std::cout << input << std::endl;
}
}
// Restore terminal attributes on macOS
restoreTerminalAttributes();
std::cout << "Loop Over." << std::endl;
return 0;
}