简单地将kbhit移植到linux中 [英] porting kbhit into linux simply
问题描述
嗨
我正在尝试将一个大型CPP项目移植到linux中以在Raspberry Pi上运行。
PROG_WIN.CPP中的一个文件允许用户中断程序。我不得不替换旧的Borland标题
#include < conio.h >
with
#include < ncurses.h >
其中我belive应该能够直接处理getch调用(虽然我已经读取了getchar)但是使用命令g ++ -w -o和g ++链接得到以下错误:
PROG_WIN.CPP:在函数'int user_pressed_escape()'中:
PROG_WIN.CPP:69:14:错误:'kbhit'未在此范围内声明
我假设ncurses.h文件中没有函数kbhit,因此没有声明或defi这个功能的用途。是否有一个快速的解决方法,为kbhit插入一个等效的函数?
感谢您的任何想法!
以下是CPP代码:
#include < stdio。 h >
#include < string.h >
#include < math.h >
// #include< conio.h>
#include < ncurses.h >
#include < ctype.h >
#include < stdlib.h >
#include const.h //系统,限制常数,typedef,structs
#include classes.h //包括所有类标题
#include funcdefs.h //函数原型
// extern int show_progress; //必须更改此
int show_progress;
void make_progress_window( char *)
{
return ;
}
void destroy_progress_window()
{
返回;
}
void write_progress( char * msg)
{
if (msg == NULL)
return ;
printf( \ n%s,msg);
}
void write_non_progress( char *)
{
return ;
}
int user_pressed_escape()
{
int 键;
if (kbhit()){ // 是否按下了键?
key = getch(); // 如果是这样,请阅读
而(kbhit()) // 在案例功能键中刷新键缓冲区
getch (); // 或按键被按下
返回(key == KEY_ESCAPE);
}
else
return 0 ;
}
谢谢理查德 - 我试过了两个!
对于有类似问题的其他人;这个链接似乎很有希望:
http:// forums .fedoraforum.org / showthread.php?t = 172337 [ ^ ]
Hi
I'm trying to port a large CPP project into linux to run on a Raspberry Pi.
One of the files PROG_WIN.CPP allows a user to interrupt the program. I have had to substitute an old Borland header
#include <conio.h>
with
#include <ncurses.h>
which I belive should be able to directly handle the getch call (though I have read getchar should be inserted) but am getting the following error using the command g++ -w -o with the g++ linking:
PROG_WIN.CPP: In function ‘int user_pressed_escape()’:
PROG_WIN.CPP:69:14: error: ‘kbhit’ was not declared in this scope
I'm presuming that there is no function kbhit in the ncurses.h file and therefore no declaration or definition of this function. Is there a quick workaround for inserting an equivalent function to kbhit?
Thanks for any ideas!
Here is the CPP code:
#include <stdio.h>
#include <string.h>
#include <math.h>
//#include <conio.h>
#include <ncurses.h>
#include <ctype.h>
#include <stdlib.h>
#include "const.h" // System, limitation constants, typedefs, structs
#include "classes.h" // Includes all class headers
#include "funcdefs.h" // Function prototypes
//extern int show_progress ; //had to change this
int show_progress ;
void make_progress_window ( char * )
{
return ;
}
void destroy_progress_window ()
{
return ;
}
void write_progress ( char *msg )
{
if (msg == NULL)
return ;
printf ( "\n%s", msg ) ;
}
void write_non_progress ( char * )
{
return ;
}
int user_pressed_escape ()
{
int key ;
if (kbhit()) { // Was a key pressed?
key = getch () ; // Read it if so
while (kbhit()) // Flush key buffer in case function key
getch () ; // or key was held down
return (key == KEY_ESCAPE) ;
}
else
return 0 ;
}
Thanks Richard - I have tried both!
For others with a similar problem; this link seems promising:
http://forums.fedoraforum.org/showthread.php?t=172337[^]
这篇关于简单地将kbhit移植到linux中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!