我在 C prog 中使用 ncurses,我想使用 getch() 来捕捉箭头键和转义键。
我使用 newterm、原始模式、noecho 模式和设置为 TRUE 的键盘来正确使用 getch。我可以轻松获得箭头的键码或每个键,但是当我按下 Esc 键时,我知道 getch 设置了一个约 1 秒的计时器来检查是否没有按下任何其他键。
您认为延迟可以删除或设置为零吗?
人或 IBM 文档说,当您同时使用键盘时,尝试使用 getch 进行转义是没有用的,但我想得到它...
抱歉我的英语不好,谢谢你的回答:)
我正在尝试制作一个简单的程序来检测 UP 键。这是我的c代码:
#include <stdio.h>
#include <ncurses.h>
int main() {
initscr();
noecho();
printw("hello\n");
refresh();
int ch = getch();
if (ch == KEY_UP) {
printw("up!\n");
refresh();
}
getch();
endwin();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我编译并运行程序时,它不起作用。当我按下向上键时,它就退出了。
提前致谢。
我试图通过包含以下头文件在我的 C++ 程序中使用 ncurses:
#include <curses.h>
#include <menu.h>
#include <stdlib.h>
Run Code Online (Sandbox Code Playgroud)
我正在使用 CLion IDE,这是我的 CMakeList.txt:
cmake_minimum_required(VERSION 3.6)
project(LearnC)
set(CURSES_USE_NCURSES TRUE)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(LearnC ${SOURCE_FILES})
target_link_libraries(LearnC ${CURSES_INCLUDE_DIR})
Run Code Online (Sandbox Code Playgroud)
编译进行得很顺利,但是在链接时出现以下错误:
[ 20%] Linking CXX executable LearnC
CMakeFiles/LearnC.dir/main.cpp.o: In function `main':
../LearnC/main.cpp:20: undefined reference to `initscr'
../LearnC/main.cpp:22: undefined reference to `clear'
../LearnC/main.cpp:23: undefined reference to `noecho'
../LearnC/main.cpp:24: undefined reference to `curs_set'
../LearnC/main.cpp:25: undefined reference to `cbreak'
../LearnC/main.cpp:26: undefined reference to `nl'
../LearnC/main.cpp:27: undefined reference to `stdscr'
../LearnC/main.cpp:27: undefined reference …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 TensorFlow CLI 调试器来识别在网络训练期间导致 NaN 的操作,但是当我尝试运行代码时出现错误:
_curses.error: cbreak() returned ERR
我在 Ubuntu 服务器上运行代码,我通过 SSH 连接到该服务器,并尝试按照本教程进行操作。
我曾尝试使用tf.add_check_numerics_ops(),但网络中的层包括 while 循环,因此不兼容。这是引发错误的代码部分:
import tensorflow as tf
from tensorflow.python import debug as tf_debug
...
#Prepare data
train_data, val_data, test_data = dataset.prepare_datasets(model_config)
sess = tf.Session()
sess = tf_debug.LocalCLIDebugWrapperSession(sess)
# Create iterators
handle = tf.placeholder(tf.string, shape=[])
iterator = tf.data.Iterator.from_string_handle(handle, train_data.output_types, train_data.output_shapes)
mixed_spec, voice_spec, mixed_audio, voice_audio = iterator.get_next()
training_iterator = train_data.make_initializable_iterator()
validation_iterator = val_data.make_initializable_iterator()
testing_iterator = test_data.make_initializable_iterator()
training_handle = sess.run(training_iterator.string_handle())
...
Run Code Online (Sandbox Code Playgroud)
完整的错误是:
Traceback (most …Run Code Online (Sandbox Code Playgroud) 我正在用C++编写一个简单的程序,以便在终端窗口中运行.我希望输出文本锁定在屏幕上的位置.我希望能够在一行文本中更改一行文本或一些字符,同时保持其上方和下方的其他行是静态的,而不是每个新行出现在屏幕底部并推动所有内容.我知道我已经在终端中看到过这个,我相信它是用C++完成的,但我找不到任何关于它的文档.我甚至无法想到这种类型的显示器可能被称为什么.我的google fu让我失望了; 请帮忙.如果你能告诉我使用哪些命令/库,那就太好了,但是即使能够告诉我用C++以外的编程语言完成这些命令会让我比现在更多.
有什么原因printw()会导致细分错误?
没有它,代码就可以了。坏了。它似乎并没有做任何深奥的事情,所以我不确定如何开始理解这里的错误所在。
在此先感谢您的任何建议!
#include <ncurses.h>
...
initscr();
noecho();
cbreak();
...
void draw_court()
{
move(TOP_ROW-1, LEFT_COL+4);
printw("LIVES REMAINING: 3");
int i;
for (i = 0; i < RIGHT_COL; i++)
mvaddch(TOP_ROW, LEFT_COL+i, H_LINE);
for (i = 1; i < BOT_ROW-TOP_ROW; i++)
mvaddch(TOP_ROW+i, LEFT_COL, V_LINE);
for (i = 0; i < RIGHT_COL; i++)
mvaddch(BOT_ROW, LEFT_COL+i, H_LINE);
}
Run Code Online (Sandbox Code Playgroud)
ETA:来自gdb的stacktrace:
#0 0xb778a139 in _nc_printf_string () from /lib/libncurses.so.5
#1 0xb7785e04 in vwprintw () from /lib/libncurses.so.5
#2 0xb7785f63 in printw () from /lib/libncruses.so.5
#3 0x08048f23 …Run Code Online (Sandbox Code Playgroud) 我想为mvwprint/mvwchgat ncurses函数编写一个包装函数,它在指定的窗口中打印消息,然后更改其属性.
但是,mvwchgat需要知道它应该改变多少个字符 - 而且我不知道如何告诉mvwchgat格式化的字符串有多长,因为strlen() on,"abc%d"显然会返回5,因为strlen不知道是什么%d代表 ...
我试图使用ncurses库v 5.9编译以下代码.关于Debian wheezy.但我正在未定义参考图书馆的功能.我从源代码安装了库.
#include <curses.h>
#include <menu.h>
#include<stdlib.h>
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#define CTRLD 4
char *choices[] = {
"Choice 1",
"Choice 2",
"Choice 3",
"Choice 4",
"Exit",
};
int main()
{ ITEM **my_items;
int c;
MENU *my_menu;
int n_choices, i;
ITEM *cur_item;
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
n_choices = ARRAY_SIZE(choices);
my_items = (ITEM **)calloc(n_choices + 1, sizeof(ITEM *));
for(i = 0; i < n_choices; ++i)
my_items[i] = new_item(choices[i], choices[i]);
my_items[n_choices] = (ITEM *)NULL;
my_menu = new_menu((ITEM **)my_items);
mvprintw(LINES …Run Code Online (Sandbox Code Playgroud) 这是从控制台读取密钥的简单方法
reader := bufio.NewReader(os.Stdin)
// ...
func readKey() rune {
char, _, err := reader.ReadRune()
if err != nil {
fmt.Println("Error reading key: ", err)
}
return char
}
// ...
fmt.Println("Checking keyboard input...")
loop:
for {
keyb := readKey()
switch keyb {
case 'x':
fmt.Println("x key pressed, exiting loop")
break loop
}
}
Run Code Online (Sandbox Code Playgroud)
但是,问题在于应用程序始终等待读取密钥。如果您只想等待5秒钟才能读取密钥,而又没有读取密钥,则继续应用程序怎么办?
我在想,我可能必须引入一个依赖项,例如ncurses或turbopascal所具有的称为crt并具有readkey函数的单元(模块)。但是,依赖确实是必需的吗?或者是否有简单的方法可以做到?我什至不知道甚至有一些defer()技巧。
我编写了一个程序,可以创建一个侧面滚动选框效果,它可以在我的Mac终端上完美运行.但是,当我在我的树莓派(Raspbian Linux)上运行它时,效果会混乱,并开始在新行上打印,并且不会滚动整个文本长度.谁能弄明白问题是什么?我已经试了几天了.
// Compile: gcc marquee.c -o marquee -lncurses
// Usage: ./marquee filename length row col speed
// Reads text from a file and displays 'length' number of chars
// scrolling sideways at a given 'row, col' position at some indicated 'speed'
#include <curses.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#define ROW 10
int main(int ac, char *av[])
{
if(ac != 6){
printf("marquee [fileName] [row] [col] [speed (1-99)]\n");
perror("Insuffecient argument count\n");
exit(1);
}
char message[256];
int …Run Code Online (Sandbox Code Playgroud)