212{
213#ifdef _WIN32
214 DWORD to_read{0};
215 GetNumberOfConsoleInputEvents(
Private::in.handle(), &to_read);
216 if(to_read == 0) return;
217 DWORD read{0};
218 std::vector<INPUT_RECORD> events{to_read};
219 if(!ReadConsoleInputW(
Private::in.handle(), &events[0], to_read, &read) || read != to_read)
Term::Exception(
"ReadFile() failed");
220 std::wstring ret;
221 bool need_windows_size{false};
222 for(std::size_t i = 0; i != read; ++i)
223 {
224 switch(events[i].EventType)
225 {
226 case KEY_EVENT:
227 {
228 if(events[i].Event.KeyEvent.bKeyDown)
229 {
230 if(events[i].Event.KeyEvent.uChar.UnicodeChar == 0)
read_windows_key(events[i].Event.KeyEvent.wVirtualKeyCode, events[i].Event.KeyEvent.dwControlKeyState, events[i].Event.KeyEvent.wRepeatCount);
231 else
232 ret.append(events[i].Event.KeyEvent.wRepeatCount, events[i].Event.KeyEvent.uChar.UnicodeChar ==
Term::Key::Del ?
static_cast<wchar_t>(Key(
Term::Key::Value::Backspace)) : static_cast<wchar_t>(events[i].Event.KeyEvent.uChar.UnicodeChar));
233 }
234 break;
235 }
236 case FOCUS_EVENT:
237 {
240 break;
241 }
242 case MENU_EVENT:
243 {
245 break;
246 }
247 case MOUSE_EVENT:
248 {
250 static MOUSE_EVENT_RECORD old_state;
251 if(events[i].Event.MouseEvent.dwEventFlags == MOUSE_WHEELED || events[i].Event.MouseEvent.dwEventFlags == MOUSE_HWHEELED)
252 ;
253 else if(old_state.dwButtonState == events[i].Event.MouseEvent.dwButtonState && old_state.dwMousePosition.X == events[i].Event.MouseEvent.dwMousePosition.X && old_state.dwMousePosition.Y == events[i].Event.MouseEvent.dwMousePosition.Y && old_state.dwEventFlags == events[i].Event.MouseEvent.dwEventFlags)
254 break;
255 std::int32_t state{static_cast<std::int32_t>(events[i].Event.MouseEvent.dwButtonState)};
256 switch(events[i].Event.MouseEvent.dwEventFlags)
257 {
258 case 0:
259 {
260 m_events.
push(
Term::Mouse(
setButton(
static_cast<std::int32_t
>(old_state.dwButtonState), state),
static_cast<std::uint16_t
>(events[i].Event.MouseEvent.dwMousePosition.Y),
static_cast<std::uint16_t
>(events[i].Event.MouseEvent.dwMousePosition.X)));
261 ;
262 break;
263 }
264 case MOUSE_MOVED:
265 {
266 m_events.
push(
Term::Mouse(
setButton(
static_cast<std::int32_t
>(old_state.dwButtonState), state),
static_cast<std::uint16_t
>(events[i].Event.MouseEvent.dwMousePosition.Y),
static_cast<std::uint16_t
>(events[i].Event.MouseEvent.dwMousePosition.X)));
267 ;
268 break;
269 }
270 case DOUBLE_CLICK:
271 {
273 break;
274 }
275 case MOUSE_WHEELED:
276 {
278 else
280 break;
281 }
282 case MOUSE_HWHEELED:
283 {
285 else
287 break;
288 }
289 default: break;
290 }
291 old_state = events[i].Event.MouseEvent;
292 break;
293 }
294 case WINDOW_BUFFER_SIZE_EVENT:
295 {
296 need_windows_size = true;
298 break;
299 }
300 default: break;
301 }
302 }
305#else
310#endif
311}