2020-03-01 17:30:00 +00:00
|
|
|
namespace mwmp_input {
|
2021-03-21 13:45:01 +00:00
|
|
|
std::string windowInputBuffer;
|
2020-03-01 17:30:00 +00:00
|
|
|
void handler() {
|
|
|
|
char c;
|
2020-03-02 13:19:00 +00:00
|
|
|
#ifndef WIN32
|
2020-03-01 17:30:00 +00:00
|
|
|
while (kbhit()) {
|
|
|
|
c = getch();
|
2020-03-02 13:19:00 +00:00
|
|
|
#else // on Windows conio.h getch() and kbhit() are deprecated, use _getch() and _kbhit() instead
|
2020-03-01 17:30:00 +00:00
|
|
|
while (_kbhit()) {
|
|
|
|
c = _getch();
|
|
|
|
#endif
|
2021-03-21 13:45:01 +00:00
|
|
|
std::cout << c << std::flush;
|
2020-03-01 17:30:00 +00:00
|
|
|
if (c == '\n' || c == '\r') { // handle carriage return as new line on Windows
|
2021-03-21 13:45:01 +00:00
|
|
|
std::cout << std::endl;
|
2020-03-01 17:30:00 +00:00
|
|
|
Script::Call<Script::CallbackIdentity("OnServerWindowInput")>(windowInputBuffer.c_str());
|
|
|
|
windowInputBuffer.assign("");
|
|
|
|
}
|
2020-03-02 13:19:00 +00:00
|
|
|
else if (c == '\b') {
|
2020-03-02 13:40:00 +00:00
|
|
|
auto size = windowInputBuffer.size();
|
|
|
|
if (size > 0)
|
|
|
|
windowInputBuffer.erase(size - 1);
|
2020-03-02 13:19:00 +00:00
|
|
|
}
|
2020-03-01 17:30:00 +00:00
|
|
|
else windowInputBuffer += c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|