From fb515768cae574d3343d5774b6ca20c7fff6c60a Mon Sep 17 00:00:00 2001 From: Ryo Suzuki Date: Mon, 23 Dec 2024 16:26:38 +0900 Subject: [PATCH] Improve console https://github.com/Siv3D/OpenSiv3D/issues/1254 --- .../WindowsDesktop/Siv3D/Console/CConsole.cpp | 23 ++++++++++++++++++- .../WindowsDesktop/Siv3D/Console/CConsole.hpp | 2 ++ .../WindowsDesktop/Siv3D/Window/CWindow.cpp | 6 +++++ .../macOS_Linux/Siv3D/Console/CConsole.cpp | 2 ++ .../macOS_Linux/Siv3D/Console/CConsole.hpp | 2 ++ Siv3D/src/Siv3D/Console/IConsole.hpp | 2 ++ 6 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Console/CConsole.cpp b/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Console/CConsole.cpp index e583768a..64cf2bee 100644 --- a/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Console/CConsole.cpp +++ b/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Console/CConsole.cpp @@ -12,7 +12,7 @@ # include # include # include -# include +# include # include "CConsole.hpp" # include # include @@ -126,6 +126,27 @@ namespace s3d } } + //////////////////////////////////////////////////////////////// + // + // clearSelection + // + //////////////////////////////////////////////////////////////// + + void CConsole::clearSelection() + { + if (not m_isOpen) + { + return; + } + + if (HWND hConsoleWindow = ::GetConsoleWindow()) + { + // ESC キーを送信 + ::SendMessage(hConsoleWindow, WM_KEYDOWN, VK_ESCAPE, 0); + ::SendMessage(hConsoleWindow, WM_KEYUP, VK_ESCAPE, 0); + } + } + //////////////////////////////////////////////////////////////// // // close diff --git a/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Console/CConsole.hpp b/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Console/CConsole.hpp index 4cdecdac..4de33440 100644 --- a/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Console/CConsole.hpp +++ b/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Console/CConsole.hpp @@ -27,6 +27,8 @@ namespace s3d bool attach() override; + void clearSelection() override; + void close() override; private: diff --git a/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Window/CWindow.cpp b/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Window/CWindow.cpp index a7bd5050..77ae4b57 100644 --- a/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Window/CWindow.cpp +++ b/Siv3D/src/Siv3D-Platform/WindowsDesktop/Siv3D/Window/CWindow.cpp @@ -17,6 +17,7 @@ # include # include # include +# include # include # include # include @@ -538,6 +539,11 @@ namespace s3d SIV3D_ENGINE(UserAction)->reportUserActions(UserAction::WindowDeactivated); } + if (focused) + { + SIV3D_ENGINE(Console)->clearSelection(); + } + m_state.focused = focused; } diff --git a/Siv3D/src/Siv3D-Platform/macOS_Linux/Siv3D/Console/CConsole.cpp b/Siv3D/src/Siv3D-Platform/macOS_Linux/Siv3D/Console/CConsole.cpp index 0a00c4c4..90332f6e 100644 --- a/Siv3D/src/Siv3D-Platform/macOS_Linux/Siv3D/Console/CConsole.cpp +++ b/Siv3D/src/Siv3D-Platform/macOS_Linux/Siv3D/Console/CConsole.cpp @@ -26,5 +26,7 @@ namespace s3d return true; } + void CConsole::clearSelection() {} + void CConsole::close() {} } diff --git a/Siv3D/src/Siv3D-Platform/macOS_Linux/Siv3D/Console/CConsole.hpp b/Siv3D/src/Siv3D-Platform/macOS_Linux/Siv3D/Console/CConsole.hpp index 4c66fc2c..e68034b3 100644 --- a/Siv3D/src/Siv3D-Platform/macOS_Linux/Siv3D/Console/CConsole.hpp +++ b/Siv3D/src/Siv3D-Platform/macOS_Linux/Siv3D/Console/CConsole.hpp @@ -24,6 +24,8 @@ namespace s3d bool attach() override; + void clearSelection() override; + void close() override; }; } diff --git a/Siv3D/src/Siv3D/Console/IConsole.hpp b/Siv3D/src/Siv3D/Console/IConsole.hpp index aa64e5bc..bce2f826 100644 --- a/Siv3D/src/Siv3D/Console/IConsole.hpp +++ b/Siv3D/src/Siv3D/Console/IConsole.hpp @@ -27,6 +27,8 @@ namespace s3d virtual bool attach() = 0; + virtual void clearSelection() = 0; + virtual void close() = 0; }; }