Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 增加与 getch_console 配套的 kbhit_console #235

Merged
merged 2 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading