1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 17:19:56 +00:00
openmw-tes3mp/apps/openmw-mp/handleInput.cpp
2020-03-15 17:30:00 +01:00

27 lines
899 B
C++

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