Skip to content

Commit

Permalink
feat: 增加与 getch_console 配套的 kbhit_console (#235)
Browse files Browse the repository at this point in the history
* feat: 增加与 getch_console 配套的 kbhit_console

* adjust: 增加 ege_getch() 和 ege_kbhit()
  • Loading branch information
yixy-only authored Oct 12, 2024
1 parent 2527cf2 commit e004364
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
24 changes: 14 additions & 10 deletions include/ege.h
Original file line number Diff line number Diff line change
Expand Up @@ -1197,14 +1197,15 @@ ege_point EGEAPI ege_transform_calc(float x, float y, PIMAGE pimg = NULL); // C
// It is not supported in VC 6.0.
#ifndef EGE_COMPILERINFO_VC6
// Console
bool init_console(); // Initialize the console
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
bool EGEAPI init_console(); // Initialize the console
bool EGEAPI clear_console(); // Clear the console
bool EGEAPI show_console(); // Show the Console
bool EGEAPI hide_console(); // Hide the console
bool EGEAPI close_console(); // Close the console and restore the old STD I/O
#endif

int getch_console(); // Used instead of the getch() function in <conio.h>
int EGEAPI getch_console(); // Replace the getch() function in <conio.h>
int EGEAPI kbhit_console(); // Replace the kbhit() function in <conio.h>

void EGEAPI ege_sleep (long ms);
void EGEAPI delay (long ms);
Expand Down Expand Up @@ -1519,14 +1520,17 @@ int EGEAPI kbhitEx(int flag);
int EGEAPI keystate(int key);
void EGEAPI flushkey();

int EGEAPI ege_getch();
int EGEAPI ege_kbhit();

#if !defined(_INC_CONIO) && !defined(_CONIO_H_)
#define _INC_CONIO
#define _CONIO_H_
int EGEAPI getch();
int EGEAPI kbhit();
int EGEAPI getch(); // Same as ege_getch()
int EGEAPI kbhit(); // Same as ege_kbhit()
#else
#define getch getchEx
#define kbhit kbhitEx
#define getch ege_getch
#define kbhit ege_kbhit
#endif

int EGEAPI mousemsg();
Expand Down
9 changes: 9 additions & 0 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,13 @@ int getch_console()
#endif
}

int kbhit_console()
{
#ifdef MSVC_VER
return ::_kbhit();
#else
return ::kbhit();
#endif
}

} // namespace ege
14 changes: 12 additions & 2 deletions src/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,26 @@ int getchEx(int flag)
return 0;
}

int kbhit()
int ege_kbhit()
{
return kbhitEx(0);
}

int getch()
int ege_getch()
{
return getchEx(0);
}

int kbhit()
{
return ege_kbhit();
}

int getch()
{
return ege_getch();
}

key_msg getkey()
{
struct _graph_setting* pg = &graph_setting;
Expand Down

0 comments on commit e004364

Please sign in to comment.