diff --git a/src/window_callbacks.cpp b/src/window_callbacks.cpp index 9fffe903..487ce33c 100644 --- a/src/window_callbacks.cpp +++ b/src/window_callbacks.cpp @@ -140,7 +140,7 @@ void WindowCallbacks::onTouchEnd(int id, double x, double y) { } } void WindowCallbacks::onKeyboard(KeyCode key, KeyAction action) { - if(hasInputMode(InputMode::Mouse)) { + if(sendEvents) { // return onKeyboard((KeyCode) 4, KeyAction::PRESS); // key = (KeyCode) 0x21; #ifdef __APPLE__ @@ -188,20 +188,26 @@ void WindowCallbacks::onKeyboard(KeyCode key, KeyAction action) { } } void WindowCallbacks::onKeyboardText(std::string const& c) { - if(c == "\n" && !jniSupport.getTextInputHandler().isMultiline()) - jniSupport.onReturnKeyPressed(); - else - jniSupport.getTextInputHandler().onTextInput(c); + if(sendEvents) { + if(c == "\n" && !jniSupport.getTextInputHandler().isMultiline()) { + jniSupport.onReturnKeyPressed(); + } else { + jniSupport.getTextInputHandler().onTextInput(c); + } + } } void WindowCallbacks::onPaste(std::string const& str) { - jniSupport.getTextInputHandler().onTextInput(str); + if(sendEvents) { + jniSupport.getTextInputHandler().onTextInput(str); + } } void WindowCallbacks::onGamepadState(int gamepad, bool connected) { Log::trace("WindowCallbacks", "Gamepad %s #%i", connected ? "connected" : "disconnected", gamepad); - if(connected) + if(connected) { gamepads.insert({gamepad, GamepadData()}); - else + } else { gamepads.erase(gamepad); + } if(sendEvents) { // This crashs the game 1.16.210+ during init, but works after loading @@ -212,8 +218,9 @@ void WindowCallbacks::onGamepadState(int gamepad, bool connected) { } void WindowCallbacks::queueGamepadAxisInputIfNeeded(int gamepad) { - if(!needsQueueGamepadInput) + if(!needsQueueGamepadInput) { return; + } inputQueue.addEvent(FakeMotionEvent(AINPUT_SOURCE_GAMEPAD, gamepad, AMOTION_EVENT_ACTION_MOVE, 0, 0.f, 0.f, [this, gamepad](int axis) { auto gpi = gamepads.find(gamepad); diff --git a/src/window_callbacks.h b/src/window_callbacks.h index 5f2f7533..f1db5a67 100644 --- a/src/window_callbacks.h +++ b/src/window_callbacks.h @@ -25,10 +25,11 @@ class WindowCallbacks { bool needsQueueGamepadInput = true; bool fullscreen = options.fullscreen; bool sendEvents = false; + // Prefer Touch, Gamepad over Mouse due to Input Emulation enum class InputMode { Touch, - Mouse, Gamepad, + Mouse, Unknown, }; InputMode inputMode = InputMode::Unknown;