admin管理员组文章数量:1393310
Im trying to create a Menu in c++ that is capable of working in linux and ubuntu, the problem is i can't turn the echo back on in widows my current library to work with the terminal looks like this.
#ifndef TC_H
#define TC_H
#include <unistd.h>
#ifdef _WIN32
#include<windows.h>
#include<conio.h>
#define getchar _getch
#define TRAIL_CHR 224
#define ARROW_UP 72
#define ARROW_DOWN 80
#define ARROW_RIGHT 77
#define ARROW_LEFT 75
#define ENTR 13
DWORD mode;
void tc_echo_off() {
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
if (hStdin == INVALID_HANDLE_VALUE) {
std::cerr << "Couldn't get the standard input handle" << std::endl;
}
DWORD mode;
if (GetConsoleMode(hStdin, &mode)) {
std::cerr << "Couldn't get the standard input handle" << std::endl;
}
mode &= ~ENABLE_ECHO_INPUT; // Disable echo
SetConsoleMode(hStdin, mode);
}
void tc_echo_on() {
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
if (hStdin == INVALID_HANDLE_VALUE) {
std::cerr << "Couldn't get the standard input handle" << std::endl;
}
DWORD mode;
if (GetConsoleMode(hStdin, &mode) != 0) {
std::cerr << "Failed to get console mode" << std::endl;
}
mode |= ENABLE_ECHO_INPUT; // Enable echo
SetConsoleMode(hStdin, mode);
}
#else
#include <sys/ioctl.h>
#include <termios.h>
#define TRAIL_CHR (c == 27 && getchar()==91)
#define ARROW_UP 65
#define ARROW_DOWN 66
#define ARROW_RIGHT 67
#define ARROW_LEFT 68
#define ENTR 10
void tc_echo_off(){
struct termios term;
tcgetattr(1, &term);
term.c_lflag &= ~(ICANON|ECHO);
tcsetattr(1, TCSANOW, &term);
}
void tc_echo_on(){
struct termios term;
tcgetattr(1, &term);
term.c_lflag |= (ECHO|ICANON);
tcsetattr(1, TCSANOW, &term);
}
#endif
#endif //TC_H
I tried to take the mode variable out of the tc_echo_off function but it didn't work.
本文标签: How can i enable and disable the echo in windows terminal using cStack Overflow
版权声明:本文标题:How can i enable and disable the echo in windows terminal using c++ - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744656700a2618008.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论