[英]Efficent way of breaking a string into an array based on a character eg.% in C?
[英]Is there a better way to analyze the key which was pressed without printing on the screen in C (eg. Arrow keys and Return)?
代碼段(此處為完整代碼。) :
int Process (void)
{
for (;;)
{
unsigned char Char_Fore = getch();
if (Char_Fore == 0xE0)
{
unsigned char Char_Back = getch();
switch (Char_Back)
{
case 0x48:
Up();
break;
case 0x50:
Down();
break;
}
}
else if (Char_Fore == 0x0D)
Enter();
}
return 0;
}
這段代碼可以在某些機器上正常運行,但有些因為getch()
函數而無法運行。
getch()
或_getch()
是在conio.h
聲明的函數,如果鍵盤不是IBM set 2,或者選擇了不同的編譯器(不是Mingw-gcc),返回值會有所不同。
是否有更好的方法來分析在C中按下的鍵而不在屏幕上打印並且在控制台中不使用像getch()
或_getch()
這樣的棄用函數?
我知道這並不是真正的答案,但我沒有足夠的聲譽來發表評論。
我記得使用一個名為termios.h的標題,並使用它我可以關閉字符回顯,現在這是在UNIX系統上,但我想有一個Windows等價物。
這是windows.h的pressanykey代碼,也許您可以根據需要進行調整? http://www.cplusplus.com/forum/articles/7312/#msg33734
查看curses或ncurses ,聽起來像你想要使用的東西。
PDCurses似乎是Windows選項 - ncurses是否可用於Windows?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.