Input.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Context.h"
  24. #include "CoreEvents.h"
  25. #include "Graphics.h"
  26. #include "GraphicsEvents.h"
  27. #include "Input.h"
  28. #include "Log.h"
  29. #include "Profiler.h"
  30. #include <cstring>
  31. #ifndef USE_SDL
  32. #include <Windows.h>
  33. #else
  34. #include <SDL.h>
  35. #endif
  36. #include "DebugNew.h"
  37. OBJECTTYPESTATIC(Input);
  38. Input::Input(Context* context) :
  39. Object(context),
  40. clipCursor_(true),
  41. showCursor_(true),
  42. toggleFullscreen_(true),
  43. active_(false),
  44. minimized_(false),
  45. activated_(false),
  46. suppressNextChar_(false),
  47. initialized_(false)
  48. {
  49. // Zero the initial state
  50. mouseButtonDown_ = 0;
  51. mouseButtonPress_ = 0;
  52. lastMousePosition_ = IntVector2::ZERO;
  53. #ifndef USE_SDL
  54. SubscribeToEvent(E_WINDOWMESSAGE, HANDLER(Input, HandleWindowMessage));
  55. #endif
  56. SubscribeToEvent(E_SCREENMODE, HANDLER(Input, HandleScreenMode));
  57. SubscribeToEvent(E_BEGINFRAME, HANDLER(Input, HandleBeginFrame));
  58. // Try to initialize right now, but skip if screen mode is not yet set
  59. Initialize();
  60. }
  61. Input::~Input()
  62. {
  63. }
  64. void Input::Update()
  65. {
  66. PROFILE(UpdateInput);
  67. if (!graphics_)
  68. return;
  69. // Reset current state
  70. keyPress_.Clear();
  71. mouseButtonPress_ = 0;
  72. mouseMove_ = IntVector2::ZERO;
  73. mouseMoveWheel_ = 0;
  74. #ifndef USE_SDL
  75. // Pump Win32 events
  76. MSG msg;
  77. while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
  78. {
  79. TranslateMessage(&msg);
  80. DispatchMessage(&msg);
  81. }
  82. #else
  83. // Pump SDL events
  84. SDL_Event evt;
  85. SDL_PumpEvents();
  86. while (SDL_PollEvent(&evt))
  87. HandleSDLEvent(&evt);
  88. // Poll SDL activation state
  89. unsigned state = SDL_GetAppState();
  90. if ((state & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) == (SDL_APPINPUTFOCUS | SDL_APPACTIVE))
  91. {
  92. if (!active_)
  93. activated_ = true;
  94. }
  95. else
  96. {
  97. if (active_)
  98. MakeInactive();
  99. }
  100. #endif
  101. // Activate application now if necessary
  102. if (activated_)
  103. MakeActive();
  104. // Finally send mouse move event
  105. if (active_)
  106. {
  107. // Recenter the mouse cursor manually if cursor clipping is in effect
  108. #ifndef USE_SDL
  109. IntVector2 mousePos = GetMousePosition();
  110. mouseMove_ = mousePos - lastMousePosition_;
  111. if ((clipCursor_) && (mouseMove_ != IntVector2::ZERO))
  112. {
  113. IntVector2 center(graphics_->GetWidth() / 2, graphics_->GetHeight() / 2);
  114. SetMousePosition(center);
  115. lastMousePosition_ = GetMousePosition();
  116. }
  117. else
  118. lastMousePosition_ = mousePos;
  119. #else
  120. if ((clipCursor_) && (mouseMove_ != IntVector2::ZERO))
  121. {
  122. IntVector2 center(graphics_->GetWidth() / 2, graphics_->GetHeight() / 2);
  123. SetMousePosition(center);
  124. lastMousePosition_ = GetMousePosition();
  125. }
  126. #endif
  127. if (mouseMove_ != IntVector2::ZERO)
  128. {
  129. using namespace MouseMove;
  130. VariantMap eventData;
  131. eventData[P_X] = lastMousePosition_.x_;
  132. eventData[P_Y] = lastMousePosition_.y_;
  133. eventData[P_DX] = mouseMove_.x_;
  134. eventData[P_DY] = mouseMove_.y_;
  135. eventData[P_BUTTONS] = mouseButtonDown_;
  136. eventData[P_QUALIFIERS] = GetQualifiers();
  137. eventData[P_CLIPCURSOR] = clipCursor_;
  138. SendEvent(E_MOUSEMOVE, eventData);
  139. }
  140. }
  141. }
  142. void Input::SetClipCursor(bool enable)
  143. {
  144. clipCursor_ = enable;
  145. if (!graphics_)
  146. return;
  147. if ((!graphics_->GetFullscreen()) && (active_) && (clipCursor_))
  148. {
  149. SetMousePosition(graphics_->GetWidth() / 2, graphics_->GetHeight() / 2);
  150. lastMousePosition_ = GetMousePosition();
  151. #ifndef USE_SDL
  152. RECT clipRect;
  153. GetWindowRect((HWND)graphics_->GetWindowHandle(), &clipRect);
  154. ClipCursor(&clipRect);
  155. #endif
  156. }
  157. else
  158. {
  159. if ((graphics_->GetFullscreen()) && (active_) && (clipCursor_))
  160. {
  161. SetMousePosition(graphics_->GetWidth() / 2, graphics_->GetHeight() / 2);
  162. lastMousePosition_ = GetMousePosition();
  163. }
  164. #ifndef USE_SDL
  165. ClipCursor(0);
  166. #endif
  167. }
  168. }
  169. void Input::SetToggleFullscreen(bool enable)
  170. {
  171. toggleFullscreen_ = enable;
  172. }
  173. void Input::SetMousePosition(const IntVector2& position)
  174. {
  175. if (!graphics_)
  176. return;
  177. #ifndef USE_SDL
  178. POINT point;
  179. point.x = position.x_;
  180. point.y = position.y_;
  181. ClientToScreen((HWND)graphics_->GetWindowHandle(), &point);
  182. SetCursorPos(point.x, point.y);
  183. #else
  184. SDL_WarpMouse(position.x_, position.y_);
  185. #endif
  186. }
  187. void Input::SetMousePosition(int x, int y)
  188. {
  189. SetMousePosition(IntVector2(x, y));
  190. }
  191. void Input::SuppressNextChar()
  192. {
  193. suppressNextChar_ = true;
  194. }
  195. bool Input::GetKeyDown(int key) const
  196. {
  197. return keyDown_.Contains(key);
  198. }
  199. bool Input::GetKeyPress(int key) const
  200. {
  201. return keyPress_.Contains(key);
  202. }
  203. IntVector2 Input::GetMousePosition() const
  204. {
  205. IntVector2 ret(0, 0);
  206. if (!graphics_)
  207. return ret;
  208. #ifndef USE_SDL
  209. POINT mouse;
  210. GetCursorPos(&mouse);
  211. ScreenToClient((HWND)graphics_->GetWindowHandle(), &mouse);
  212. ret.x_ = mouse.x;
  213. ret.y_ = mouse.y;
  214. #else
  215. SDL_GetMouseState(&ret.x_, &ret.y_);
  216. #endif
  217. return ret;
  218. }
  219. bool Input::GetMouseButtonDown(int button) const
  220. {
  221. return (mouseButtonDown_ & button) != 0;
  222. }
  223. bool Input::GetMouseButtonPress(int button) const
  224. {
  225. return (mouseButtonPress_ & button) != 0;
  226. }
  227. bool Input::GetQualifierDown(int qualifier) const
  228. {
  229. #ifndef USE_SDL
  230. if (qualifier == QUAL_SHIFT)
  231. return GetKeyDown(KEY_SHIFT);
  232. if (qualifier == QUAL_CTRL)
  233. return GetKeyDown(KEY_CTRL);
  234. if (qualifier == QUAL_ALT)
  235. return GetKeyDown(KEY_ALT);
  236. #else
  237. if (qualifier == QUAL_SHIFT)
  238. return GetKeyDown(KEY_LSHIFT) || GetKeyDown(KEY_RSHIFT);
  239. if (qualifier == QUAL_CTRL)
  240. return GetKeyDown(KEY_LCTRL) || GetKeyDown(KEY_RCTRL);
  241. if (qualifier == QUAL_ALT)
  242. return GetKeyDown(KEY_LALT) || GetKeyDown(KEY_RALT);
  243. #endif
  244. return false;
  245. }
  246. bool Input::GetQualifierPress(int qualifier) const
  247. {
  248. #ifndef USE_SDL
  249. if (qualifier == QUAL_SHIFT)
  250. return GetKeyPress(KEY_SHIFT);
  251. if (qualifier == QUAL_CTRL)
  252. return GetKeyPress(KEY_CTRL);
  253. if (qualifier == QUAL_ALT)
  254. return GetKeyPress(KEY_ALT);
  255. #else
  256. if (qualifier == QUAL_SHIFT)
  257. return GetKeyPress(KEY_LSHIFT) || GetKeyPress(KEY_RSHIFT);
  258. if (qualifier == QUAL_CTRL)
  259. return GetKeyPress(KEY_LCTRL) || GetKeyPress(KEY_RCTRL);
  260. if (qualifier == QUAL_ALT)
  261. return GetKeyPress(KEY_LALT) || GetKeyPress(KEY_RALT);
  262. #endif
  263. return false;
  264. }
  265. int Input::GetQualifiers() const
  266. {
  267. int ret = 0;
  268. if (GetQualifierDown(QUAL_SHIFT))
  269. ret |= QUAL_SHIFT;
  270. if (GetQualifierDown(QUAL_CTRL))
  271. ret |= QUAL_CTRL;
  272. if (GetQualifierDown(QUAL_ALT))
  273. ret |= QUAL_ALT;
  274. return ret;
  275. }
  276. void Input::Initialize()
  277. {
  278. Graphics* graphics = GetSubsystem<Graphics>();
  279. if ((!graphics) || (!graphics->IsInitialized()))
  280. return;
  281. graphics_ = graphics;
  282. // In fullscreen mode there is no initial window activation message. Therefore assume activation
  283. #ifndef USE_SDL
  284. if (graphics_->GetFullscreen())
  285. activated_ = true;
  286. #else
  287. SDL_EnableUNICODE(SDL_TRUE);
  288. // For SDL, we never want to show the operating system cursor inside our window
  289. SDL_ShowCursor(SDL_DISABLE);
  290. showCursor_ = false;
  291. #endif
  292. initialized_ = true;
  293. LOGINFO("Initialized input");
  294. }
  295. void Input::MakeActive()
  296. {
  297. if (!graphics_)
  298. return;
  299. ResetState();
  300. active_ = true;
  301. activated_ = false;
  302. // Re-establish mouse cursor clipping if necessary
  303. SetClipCursor(clipCursor_);
  304. SetCursorVisible(false);
  305. using namespace Activation;
  306. VariantMap eventData;
  307. eventData[P_ACTIVE] = active_;
  308. eventData[P_MINIMIZED] = minimized_;
  309. SendEvent(E_ACTIVATION, eventData);
  310. }
  311. void Input::MakeInactive()
  312. {
  313. if (!graphics_)
  314. return;
  315. ResetState();
  316. active_ = false;
  317. activated_ = false;
  318. // Free and show the mouse cursor
  319. #ifndef USE_SDL
  320. ReleaseCapture();
  321. ClipCursor(0);
  322. SetCursorVisible(true);
  323. #endif
  324. using namespace Activation;
  325. VariantMap eventData;
  326. eventData[P_ACTIVE] = active_;
  327. eventData[P_MINIMIZED] = minimized_;
  328. SendEvent(E_ACTIVATION, eventData);
  329. }
  330. void Input::ResetState()
  331. {
  332. keyDown_.Clear();
  333. keyPress_.Clear();
  334. // Use SetMouseButton() to reset the state so that mouse events will be sent properly
  335. SetMouseButton(MOUSEB_LEFT, false);
  336. SetMouseButton(MOUSEB_RIGHT, false);
  337. SetMouseButton(MOUSEB_MIDDLE, false);
  338. mouseMove_ = IntVector2::ZERO;
  339. mouseMoveWheel_ = 0;
  340. mouseButtonPress_ = 0;
  341. }
  342. void Input::SetMouseButton(int button, bool newState)
  343. {
  344. // If we are not active yet, do not react to the mouse button down
  345. if ((newState) && (!active_))
  346. return;
  347. if (newState)
  348. {
  349. if (!(mouseButtonDown_ & button))
  350. mouseButtonPress_ |= button;
  351. mouseButtonDown_ |= button;
  352. }
  353. else
  354. {
  355. if (!(mouseButtonDown_ & button))
  356. return;
  357. mouseButtonDown_ &= ~button;
  358. }
  359. using namespace MouseButtonDown;
  360. VariantMap eventData;
  361. eventData[P_BUTTON] = button;
  362. eventData[P_BUTTONS] = mouseButtonDown_;
  363. eventData[P_QUALIFIERS] = GetQualifiers();
  364. SendEvent(newState ? E_MOUSEBUTTONDOWN : E_MOUSEBUTTONUP, eventData);
  365. #ifndef USE_SDL
  366. // In non-confined mode, while any of the mouse buttons are down, capture the mouse so that we get the button release reliably
  367. if ((graphics_) && (!clipCursor_))
  368. {
  369. if (mouseButtonDown_)
  370. SetCapture((HWND)graphics_->GetWindowHandle());
  371. else
  372. ReleaseCapture();
  373. }
  374. #endif
  375. }
  376. void Input::SetKey(int key, int scanCode, bool newState)
  377. {
  378. bool repeat = false;
  379. if (newState)
  380. {
  381. if (!keyDown_.Contains(key))
  382. {
  383. keyDown_.Insert(key);
  384. keyPress_.Insert(key);
  385. }
  386. else
  387. repeat = true;
  388. }
  389. else
  390. {
  391. if (!keyDown_.Erase(key))
  392. return;
  393. }
  394. using namespace KeyDown;
  395. VariantMap eventData;
  396. eventData[P_KEY] = key;
  397. eventData[P_SCANCODE] = scanCode;
  398. eventData[P_BUTTONS] = mouseButtonDown_;
  399. eventData[P_QUALIFIERS] = GetQualifiers();
  400. if (newState)
  401. eventData[P_REPEAT] = repeat;
  402. SendEvent(newState ? E_KEYDOWN : E_KEYUP, eventData);
  403. }
  404. void Input::SetMouseWheel(int delta)
  405. {
  406. if (!active_)
  407. return;
  408. if (delta)
  409. {
  410. mouseMoveWheel_ += delta;
  411. using namespace MouseWheel;
  412. VariantMap eventData;
  413. eventData[P_WHEEL] = delta;
  414. eventData[P_BUTTONS] = mouseButtonDown_;
  415. eventData[P_QUALIFIERS] = GetQualifiers();
  416. SendEvent(E_MOUSEWHEEL, eventData);
  417. }
  418. }
  419. void Input::SetCursorVisible(bool enable)
  420. {
  421. if (!graphics_)
  422. return;
  423. #ifndef USE_SDL
  424. // When inactive, always show the cursor
  425. if (!active_)
  426. enable = true;
  427. if (showCursor_ == enable)
  428. return;
  429. ShowCursor(enable ? TRUE : FALSE);
  430. showCursor_ = enable;
  431. #endif
  432. }
  433. #ifndef USE_SDL
  434. void Input::HandleWindowMessage(StringHash eventType, VariantMap& eventData)
  435. {
  436. using namespace WindowMessage;
  437. int msg = eventData[P_MSG].GetInt();
  438. int wParam = eventData[P_WPARAM].GetInt();
  439. int lParam = eventData[P_LPARAM].GetInt();
  440. switch (msg)
  441. {
  442. case WM_LBUTTONDOWN:
  443. SetMouseButton(MOUSEB_LEFT, true);
  444. eventData[P_HANDLED] = true;
  445. break;
  446. case WM_NCLBUTTONUP:
  447. case WM_LBUTTONUP:
  448. SetMouseButton(MOUSEB_LEFT, false);
  449. eventData[P_HANDLED] = true;
  450. break;
  451. case WM_RBUTTONDOWN:
  452. SetMouseButton(MOUSEB_RIGHT, true);
  453. eventData[P_HANDLED] = true;
  454. break;
  455. case WM_NCRBUTTONUP:
  456. case WM_RBUTTONUP:
  457. SetMouseButton(MOUSEB_RIGHT, false);
  458. eventData[P_HANDLED] = true;
  459. break;
  460. case WM_MBUTTONDOWN:
  461. SetMouseButton(MOUSEB_MIDDLE, true);
  462. eventData[P_HANDLED] = true;
  463. break;
  464. case WM_NCMBUTTONUP:
  465. case WM_MBUTTONUP:
  466. SetMouseButton(MOUSEB_MIDDLE, false);
  467. eventData[P_HANDLED] = true;
  468. break;
  469. case WM_MOUSEWHEEL:
  470. SetMouseWheel(wParam >> 16);
  471. eventData[P_HANDLED] = true;
  472. break;
  473. case WM_ACTIVATE:
  474. minimized_ = HIWORD(wParam) != 0;
  475. if (LOWORD(wParam) == WA_INACTIVE)
  476. MakeInactive();
  477. else
  478. {
  479. if (!minimized_)
  480. activated_ = true;
  481. }
  482. eventData[P_HANDLED] = true;
  483. break;
  484. case WM_KEYDOWN:
  485. SetKey(wParam, (lParam >> 16) & 255, true);
  486. eventData[P_HANDLED] = true;
  487. break;
  488. case WM_SYSKEYDOWN:
  489. SetKey(wParam, (lParam >> 16) & 255, true);
  490. if ((wParam == KEY_RETURN) && (toggleFullscreen_))
  491. graphics_->ToggleFullscreen();
  492. if (wParam != KEY_F4)
  493. eventData[P_HANDLED] = true;
  494. break;
  495. case WM_KEYUP:
  496. SetKey(wParam, (lParam >> 16) & 255, false);
  497. eventData[P_HANDLED] = true;
  498. break;
  499. case WM_SYSKEYUP:
  500. SetKey(wParam, (lParam >> 16) & 255, false);
  501. eventData[P_HANDLED] = true;
  502. break;
  503. case WM_CHAR:
  504. if (!suppressNextChar_)
  505. {
  506. using namespace Char;
  507. VariantMap keyEventData;
  508. keyEventData[P_CHAR] = wParam;
  509. keyEventData[P_BUTTONS] = mouseButtonDown_;
  510. keyEventData[P_QUALIFIERS] = GetQualifiers();
  511. SendEvent(E_CHAR, keyEventData);
  512. }
  513. suppressNextChar_ = false;
  514. eventData[P_HANDLED] = true;
  515. break;
  516. case WM_SETCURSOR:
  517. if ((lParam & 0xffff) == HTCLIENT)
  518. {
  519. SetCursorVisible(false);
  520. eventData[P_HANDLED] = true;
  521. }
  522. else
  523. SetCursorVisible(true);
  524. break;
  525. }
  526. }
  527. #else
  528. void Input::HandleSDLEvent(void* sdlEvent)
  529. {
  530. SDL_Event& evt = *static_cast<SDL_Event*>(sdlEvent);
  531. switch (evt.type)
  532. {
  533. case SDL_KEYDOWN:
  534. // Convert to uppercase to match Win32 virtual key codes
  535. SetKey(SDL_toupper(evt.key.keysym.sym), evt.key.keysym.scancode, true);
  536. // Check ALT-ENTER fullscreen toggle
  537. if ((evt.key.keysym.sym == KEY_RETURN) && ((GetKeyDown(KEY_LALT)) || (GetKeyDown(KEY_RALT))) && (toggleFullscreen_))
  538. graphics_->ToggleFullscreen();
  539. break;
  540. case SDL_KEYUP:
  541. SetKey(SDL_toupper(evt.key.keysym.sym), evt.key.keysym.scancode, false);
  542. break;
  543. case SDL_TEXTINPUT:
  544. // Convert back to Latin-1
  545. if (!suppressNextChar_)
  546. {
  547. unsigned char x = evt.text.text[0];
  548. unsigned char y = evt.text.text[1];
  549. int latin1 = 0;
  550. if (x < 0x80)
  551. latin1 = x;
  552. else if (x < 0xe0)
  553. latin1 = (y & 0x3f) | ((x & 0x1f) << 6);
  554. if ((latin1) && (latin1 < 256))
  555. {
  556. using namespace Char;
  557. VariantMap keyEventData;
  558. keyEventData[P_CHAR] = latin1;
  559. keyEventData[P_BUTTONS] = mouseButtonDown_;
  560. keyEventData[P_QUALIFIERS] = GetQualifiers();
  561. SendEvent(E_CHAR, keyEventData);
  562. }
  563. }
  564. else
  565. suppressNextChar_ = false;
  566. break;
  567. case SDL_MOUSEBUTTONDOWN:
  568. SetMouseButton(1 << (evt.button.button - 1), true);
  569. break;
  570. case SDL_MOUSEBUTTONUP:
  571. SetMouseButton(1 << (evt.button.button - 1), false);
  572. break;
  573. case SDL_MOUSEMOTION:
  574. mouseMove_.x_ += evt.motion.xrel;
  575. mouseMove_.y_ += evt.motion.yrel;
  576. lastMousePosition_.x_ = evt.motion.x;
  577. lastMousePosition_.y_ = evt.motion.y;
  578. break;
  579. case SDL_MOUSEWHEEL:
  580. SetMouseWheel(evt.wheel.y);
  581. break;
  582. case SDL_QUIT:
  583. if (graphics_)
  584. graphics_->Close();
  585. break;
  586. }
  587. }
  588. #endif
  589. void Input::HandleScreenMode(StringHash eventType, VariantMap& eventData)
  590. {
  591. if (!initialized_)
  592. Initialize();
  593. // Screen mode change may affect the cursor clipping behaviour. Also re-center the cursor (if needed) to the new screen size,
  594. // so that there is no erroneous mouse move event
  595. else
  596. SetClipCursor(clipCursor_);
  597. }
  598. void Input::HandleBeginFrame(StringHash eventType, VariantMap& eventData)
  599. {
  600. // Update input right at the beginning of the frame
  601. if (initialized_)
  602. Update();
  603. }