mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Added TerminateHotKey setting
This commit is contained in:
parent
88708ce398
commit
0c7358b449
@ -30,6 +30,7 @@ namespace Config
|
||||
Settings::SpriteTexCoord spriteTexCoord;
|
||||
Settings::StatsHotKey statsHotKey;
|
||||
Settings::SupportedResolutions supportedResolutions;
|
||||
Settings::TerminateHotKey terminateHotKey;
|
||||
Settings::TextureFilter textureFilter;
|
||||
Settings::ThreadPriorityBoost threadPriorityBoost;
|
||||
Settings::VSync vSync;
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <Config/Settings/SpriteTexCoord.h>
|
||||
#include <Config/Settings/StatsHotKey.h>
|
||||
#include <Config/Settings/SupportedResolutions.h>
|
||||
#include <Config/Settings/TerminateHotKey.h>
|
||||
#include <Config/Settings/TextureFilter.h>
|
||||
#include <Config/Settings/ThreadPriorityBoost.h>
|
||||
#include <Config/Settings/VSync.h>
|
||||
@ -63,6 +64,7 @@ namespace Config
|
||||
extern Settings::SpriteTexCoord spriteTexCoord;
|
||||
extern Settings::StatsHotKey statsHotKey;
|
||||
extern Settings::SupportedResolutions supportedResolutions;
|
||||
extern Settings::TerminateHotKey terminateHotKey;
|
||||
extern Settings::TextureFilter textureFilter;
|
||||
extern Settings::ThreadPriorityBoost threadPriorityBoost;
|
||||
extern Settings::VSync vSync;
|
||||
|
15
DDrawCompat/Config/Settings/TerminateHotKey.h
Normal file
15
DDrawCompat/Config/Settings/TerminateHotKey.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <Config/HotKeySetting.h>
|
||||
|
||||
namespace Config
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
class TerminateHotKey : public HotKeySetting
|
||||
{
|
||||
public:
|
||||
TerminateHotKey() : HotKeySetting("TerminateHotKey", "ctrl+alt+end") {}
|
||||
};
|
||||
}
|
||||
}
|
@ -187,6 +187,7 @@
|
||||
<ClInclude Include="Config\Settings\SpriteTexCoord.h" />
|
||||
<ClInclude Include="Config\Settings\StatsHotKey.h" />
|
||||
<ClInclude Include="Config\Settings\SupportedResolutions.h" />
|
||||
<ClInclude Include="Config\Settings\TerminateHotKey.h" />
|
||||
<ClInclude Include="Config\Settings\TextureFilter.h" />
|
||||
<ClInclude Include="Config\Settings\ThreadPriorityBoost.h" />
|
||||
<ClInclude Include="Config\Settings\VSync.h" />
|
||||
|
@ -630,6 +630,9 @@
|
||||
<ClInclude Include="Config\Settings\StatsHotKey.h">
|
||||
<Filter>Header Files\Config\Settings</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Config\Settings\TerminateHotKey.h">
|
||||
<Filter>Header Files\Config\Settings</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Gdi\Gdi.cpp">
|
||||
|
@ -148,6 +148,15 @@ namespace
|
||||
return names;
|
||||
}();
|
||||
|
||||
const std::map<std::string, UINT> g_altKeyNames = {
|
||||
{ "alt", VK_MENU },
|
||||
{ "lalt", VK_LMENU },
|
||||
{ "ralt", VK_RMENU },
|
||||
{ "ctrl", VK_CONTROL },
|
||||
{ "lctrl", VK_LCONTROL },
|
||||
{ "rctrl", VK_RCONTROL }
|
||||
};
|
||||
|
||||
bool areExcludedModifierKeysDown(const std::set<UINT>& modifiers, UINT either, UINT left, UINT right)
|
||||
{
|
||||
return modifiers.find(either) == modifiers.end() &&
|
||||
@ -156,6 +165,12 @@ namespace
|
||||
(GetAsyncKeyState(either) & 0x8000);
|
||||
}
|
||||
|
||||
UINT getKeyCode(const std::string& name, const std::map<std::string, UINT>& keyNames)
|
||||
{
|
||||
auto it = keyNames.find(name);
|
||||
return it != keyNames.end() ? it->second : 0;
|
||||
}
|
||||
|
||||
UINT getKeyCode(const std::string& name)
|
||||
{
|
||||
if (1 == name.length())
|
||||
@ -167,12 +182,22 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
auto it = g_keyNames.find(name);
|
||||
if (it == g_keyNames.end())
|
||||
auto code = getKeyCode(name, g_altKeyNames);
|
||||
if (0 == code)
|
||||
{
|
||||
throw Config::ParsingError("Invalid hotkey: '" + name + "'");
|
||||
code = getKeyCode(name, g_keyNames);
|
||||
if (0 == code)
|
||||
{
|
||||
throw Config::ParsingError("Invalid hotkey: '" + name + "'");
|
||||
}
|
||||
}
|
||||
return it->second;
|
||||
return code;
|
||||
}
|
||||
|
||||
std::string getKeyName(UINT key, const std::map<std::string, UINT>& keyNames)
|
||||
{
|
||||
auto it = std::find_if(keyNames.begin(), keyNames.end(), [&](const auto& pair) { return pair.second == key; });
|
||||
return it != keyNames.end() ? it->first : std::string();
|
||||
}
|
||||
|
||||
std::string getKeyName(UINT key)
|
||||
@ -183,8 +208,12 @@ namespace
|
||||
return std::string(1, static_cast<char>(std::tolower(key, std::locale())));
|
||||
}
|
||||
|
||||
auto it = std::find_if(g_keyNames.begin(), g_keyNames.end(), [&](const auto& pair) { return pair.second == key; });
|
||||
return it != g_keyNames.end() ? it->first : "none";
|
||||
auto name(getKeyName(key, g_altKeyNames));
|
||||
if (name.empty())
|
||||
{
|
||||
name = getKeyName(key, g_keyNames);
|
||||
}
|
||||
return name.empty() ? "none" : name;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <Common/Hook.h>
|
||||
#include <Common/Log.h>
|
||||
#include <Config/Config.h>
|
||||
#include <Dll/Dll.h>
|
||||
#include <DDraw/RealPrimarySurface.h>
|
||||
#include <Gdi/GuiThread.h>
|
||||
@ -21,6 +22,7 @@ namespace
|
||||
{
|
||||
std::function<void(void*)> action;
|
||||
void* context;
|
||||
bool onKeyDown;
|
||||
};
|
||||
|
||||
HANDLE g_bmpArrow = nullptr;
|
||||
@ -93,7 +95,7 @@ namespace
|
||||
{
|
||||
if (hotkey.first.vk == llHook->vkCode && Input::areModifierKeysDown(hotkey.first.modifiers))
|
||||
{
|
||||
if (WM_KEYDOWN == wParam || WM_SYSKEYDOWN == wParam)
|
||||
if (hotkey.second.onKeyDown == (WM_KEYDOWN == wParam || WM_SYSKEYDOWN == wParam))
|
||||
{
|
||||
hotkey.second.action(hotkey.second.context);
|
||||
}
|
||||
@ -146,6 +148,12 @@ namespace
|
||||
return CallNextHookEx(nullptr, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
void onTerminate(void* /*context*/)
|
||||
{
|
||||
LOG_INFO << "Terminating application via TerminateHotKey";
|
||||
TerminateProcess(GetCurrentProcess(), 0);
|
||||
}
|
||||
|
||||
void resetKeyboardHook()
|
||||
{
|
||||
Gdi::GuiThread::execute([]()
|
||||
@ -251,13 +259,15 @@ namespace Input
|
||||
|
||||
HOOK_FUNCTION(user32, SetWindowsHookExA, setWindowsHookExA);
|
||||
HOOK_FUNCTION(user32, SetWindowsHookExW, setWindowsHookExW);
|
||||
|
||||
registerHotKey(Config::terminateHotKey.get(), onTerminate, nullptr, false);
|
||||
}
|
||||
|
||||
void registerHotKey(const HotKey& hotKey, std::function<void(void*)> action, void* context)
|
||||
void registerHotKey(const HotKey& hotKey, std::function<void(void*)> action, void* context, bool onKeyDown)
|
||||
{
|
||||
if (0 != hotKey.vk)
|
||||
{
|
||||
g_hotKeys[hotKey] = { action, context };
|
||||
g_hotKeys[hotKey] = { action, context, onKeyDown };
|
||||
if (!g_keyboardHook)
|
||||
{
|
||||
resetKeyboardHook();
|
||||
|
@ -21,7 +21,7 @@ namespace Input
|
||||
POINT getCursorPos();
|
||||
HWND getCursorWindow();
|
||||
void installHooks();
|
||||
void registerHotKey(const HotKey& hotKey, std::function<void(void*)> action, void* context);
|
||||
void registerHotKey(const HotKey& hotKey, std::function<void(void*)> action, void* context, bool onKeydown = true);
|
||||
void setCapture(Overlay::Control* control);
|
||||
void updateCursor();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user