[Server] Pass stdin to a Lua event, fix Ctrl+C on Windows
parent
3476bd7d04
commit
4e6bcf02d2
@ -0,0 +1,24 @@
|
||||
#include <Script/Script.hpp>
|
||||
#include <Kbhit.h>
|
||||
using namespace std;
|
||||
namespace mwmp_input {
|
||||
string windowInputBuffer;
|
||||
void handler() {
|
||||
char c;
|
||||
#ifndef WIN32 // on WIndows conio.h getch() and kbhit() are deprecated, use _getch() and _kbhit() instead
|
||||
while (kbhit()) {
|
||||
c = getch();
|
||||
#else
|
||||
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 windowInputBuffer += c;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
namespace mwmp_input {
|
||||
void handler();
|
||||
}
|
Loading…
Reference in New Issue