Skip to content

Commit

Permalink
feat: 增加 getch_console() 以替代 <conio.h> 中的 getch()
Browse files Browse the repository at this point in the history
  • Loading branch information
yixy-only committed May 25, 2024
1 parent 66cdc22 commit bbbc752
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/ege.h
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ bool clear_console(); // Clear the console
bool show_console(); // Show the Console
bool hide_console(); // Hide the console
bool close_console(); // Close the console and restore the old STD I/O
int getch_console(); // Used instead of the getch() function in <conio.h>
#endif

//int EGEAPI Begin2d();
Expand Down
14 changes: 14 additions & 0 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include <fcntl.h>
#include <wincon.h>


#undef _INC_CONIO
#undef _CONIO_H_
#include <conio.h>

// macro to check whether hConsole is valid
#define CHECK_CONSOLE_HANDLE(hHandle) \
{ \
Expand Down Expand Up @@ -163,6 +168,15 @@ bool close_console()
return true;
};

int getch_console()
{
#ifdef MSVC_VER
return ::_getch();
#else
return ::getch();
#endif
}

#endif

}

0 comments on commit bbbc752

Please sign in to comment.