From 3962e55b44905d602ebc59ff2b6f399965fe38b7 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sun, 24 Jun 2018 16:54:52 -0300 Subject: [PATCH] Fix textentryscreen copypasting --- src/InputFilter.cpp | 19 +++++++++++++++++++ src/InputFilter.h | 3 +++ src/ScreenTextEntry.cpp | 41 ++++++----------------------------------- 3 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/InputFilter.cpp b/src/InputFilter.cpp index 47ee89f5ef..bb68064aaf 100644 --- a/src/InputFilter.cpp +++ b/src/InputFilter.cpp @@ -473,6 +473,21 @@ void InputFilter::UpdateMouseWheel(float _fZ) m_MouseCoords.fZ = _fZ; } +bool InputFilter::IsKBKeyPressed(DeviceButton k) const +{ + return INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, k)); +} + +bool InputFilter::IsControlPressed() const +{ + return IsKBKeyPressed(KEY_LCTRL) || IsKBKeyPressed(KEY_RCTRL); +} + +bool InputFilter::IsShiftPressed() const +{ + return IsKBKeyPressed(KEY_LSHIFT) || IsKBKeyPressed(KEY_RSHIFT); +} + // lua start #include "LuaBinding.h" @@ -506,12 +521,16 @@ class LunaInputFilter: public Luna lua_pushboolean(L, INPUTFILTER->IsBeingPressed(DeviceInput(device, button))); return 1; } + DEFINE_METHOD(IsShiftPressed, IsShiftPressed()); + DEFINE_METHOD(IsControlPressed, IsControlPressed()); LunaInputFilter() { ADD_METHOD(GetMouseX); ADD_METHOD(GetMouseY); ADD_METHOD(GetMouseWheel); ADD_METHOD(IsBeingPressed); + ADD_METHOD(IsShiftPressed); + ADD_METHOD(IsControlPressed); } }; diff --git a/src/InputFilter.h b/src/InputFilter.h index ef2ac761c0..8b11ff8ff0 100644 --- a/src/InputFilter.h +++ b/src/InputFilter.h @@ -66,6 +66,9 @@ class InputFilter // If aButtonState is NULL, use the last reported state. bool IsBeingPressed( const DeviceInput &di, const DeviceInputList *pButtonState = nullptr ) const; + bool IsKBKeyPressed(DeviceButton k) const; + bool IsControlPressed() const; + bool IsShiftPressed() const; float GetSecsHeld( const DeviceInput &di, const DeviceInputList *pButtonState = nullptr ) const; float GetLevel( const DeviceInput &di, const DeviceInputList *pButtonState = nullptr ) const; RString GetButtonComment( const DeviceInput &di ) const; diff --git a/src/ScreenTextEntry.cpp b/src/ScreenTextEntry.cpp index b936de7065..113b28ab37 100644 --- a/src/ScreenTextEntry.cpp +++ b/src/ScreenTextEntry.cpp @@ -13,6 +13,7 @@ #include "ScreenPrompt.h" #include "ScreenTextEntry.h" #include "ThemeManager.h" +#include "InputFilter.h" #include "arch/ArchHooks/ArchHooks.h" // HOOKS->GetClipboard() static const char* g_szKeys[NUM_KeyboardRow][KEYS_PER_ROW] = @@ -413,41 +414,8 @@ void ScreenTextEntry::Update( float fDelta ) bool ScreenTextEntry::Input( const InputEventPlus &input ) { - static bool bLCtrl = false, bRCtrl = false; if( IsTransitioning() ) return false; - - // bLCtrl and bRCtl are whether their respective Ctrl keys are held - // We update them here. - if( input.DeviceI == DeviceInput(DEVICE_KEYBOARD, KEY_LCTRL) ) - { - switch( input.type ) - { - case IET_FIRST_PRESS: - bLCtrl = true; - break; - case IET_RELEASE: - bLCtrl = false; - break; - default: - break; - } - } - - if( input.DeviceI == DeviceInput(DEVICE_KEYBOARD, KEY_RCTRL) ) - { - switch( input.type ) - { - case IET_FIRST_PRESS: - bRCtrl = true; - break; - case IET_RELEASE: - bRCtrl = false; - break; - default: - break; - } - } bool bHandled = false; if( input.DeviceI == DeviceInput(DEVICE_KEYBOARD, KEY_BACK) ) @@ -466,7 +434,9 @@ bool ScreenTextEntry::Input( const InputEventPlus &input ) { wchar_t c = INPUTMAN->DeviceInputToChar(input.DeviceI,true); // Detect Ctrl+V - if( ( c == L'v' || c == L'V' ) && ( bLCtrl || bRCtrl ) ) + auto ctrlPressed = INPUTFILTER->IsControlPressed(); + auto vPressed = input.DeviceI.button == KEY_CV || input.DeviceI.button == KEY_Cv; + if(vPressed && ctrlPressed) { TryAppendToAnswer( HOOKS->GetClipboard() ); @@ -476,7 +446,8 @@ bool ScreenTextEntry::Input( const InputEventPlus &input ) else if( c >= L' ' ) { // todo: handle caps lock -aj - TryAppendToAnswer( WStringToRString(wstring()+c) ); + auto str = WStringToRString(wstring() + c); + TryAppendToAnswer( str ); TextEnteredDirectly(); bHandled = true;