简体   繁体   English

如何使用NCurses阻止C ++中的某些键

[英]How can I block certain keys in C++ with NCurses

I'm new to C/C++ and I'm making a simple text user interface with NCurses . 我是C / C ++的新手,并且正在使用NCurses创建一个简单的文本用户界面。

Whenever I scroll up/down with the mouse wheel, or press arrow keys, the console echos characters like: 每当我使用鼠标滚轮上下滚动或按箭头键时,控制台都会回显类似以下字符:

"[[A^[[C^[[B^[[D" 

to show me that I've pressed the keys. 告诉我我已经按下了按键。

I would like to stop these from echoing and only echo basic keys (punctuation and letters). 我想阻止它们回显,而仅回显基本键(标点和字母)。

Here is my main loop. 这是我的主要循环。 I basically want it to be my own console with commands that I create. 我基本上希望它成为我自己创建的带有命令的控制台。

string input;
char inputArr[80];
while (input != "q" && input != "quit" && input != "exit" && input != "leave") {
    printw(" > ");
    refresh();
    getstr(inputArr);
    input = inputArr;
    if (input.substr(0, 3) != "someCommand") {
        printw("\n ~ %s\n\n", inputArr);
        refresh();
    } else
        execCmd();
}
quit();

For the most part I believe it is C++ but I do have a C function (that uses libCurl). 在大多数情况下,我相信它是C ++,但是我确实有一个C函数(使用libCurl)。

Also, is there no cleaner way to read in strings with NCurses? 另外,没有更干净的方法来使用NCurses读取字符串吗? I dont really like using char arrays (I'm used to Java). 我真的不喜欢使用char数组(我已经习惯了Java)。

Call noecho() somewhere close to initscr() . 在靠近noecho()某个地方调用noecho() initscr()

This will avoid clobbering your screen with unwanted input. 这样可以避免不必要的输入破坏屏幕。 If you want your users to see what they type later on, you will need to call echo() before, however. 如果希望用户以后看到他们键入的内容,则需要先调用echo()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM