-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFBHotkeys.cpp
More file actions
68 lines (54 loc) · 1.89 KB
/
FBHotkeys.cpp
File metadata and controls
68 lines (54 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "FBHotkeys.h"
#include <RE/Skyrim.h>
#include <SKSE/SKSE.h>
#include <spdlog/spdlog.h>
#include "FBPlugin.h"
#include "FBConfig.h"
#include <utility>
namespace {
constexpr std::uint32_t kKey_H = 35;
FBHotkeys::ReloadFn g_reload;
class HotkeySink : public RE::BSTEventSink<RE::InputEvent*> {
public:
RE::BSEventNotifyControl ProcessEvent(RE::InputEvent* const* a_event,
RE::BSTEventSource<RE::InputEvent*>*) override {
if (!a_event) {
return RE::BSEventNotifyControl::kContinue;
}
for (auto* e = *a_event; e; e = e->next) {
if (e->eventType != RE::INPUT_EVENT_TYPE::kButton) {
continue;
}
auto* btn = e->AsButtonEvent();
if (!btn) {
continue;
}
if (btn->device.get() != RE::INPUT_DEVICE::kKeyboard) {
continue;
}
if (btn->idCode != kKey_H) {
continue;
}
// initial press only
if (btn->value > 0.0f && btn->heldDownSecs == 0.0f) {
spdlog::info("[FB] Hotkey: H pressed -> Reload()");
if (g_reload) {
g_reload();
}
}
}
return RE::BSEventNotifyControl::kContinue;
}
};
HotkeySink g_sink;
}
void FBHotkeys::Install(ReloadFn reload) {
g_reload = std::move(reload);
auto* input = RE::BSInputDeviceManager::GetSingleton();
if (!input) {
spdlog::warn("[FB] Hotkeys: BSInputDeviceManager not available");
return;
}
input->AddEventSink(&g_sink);
spdlog::info("[FB] Hotkeys: installed (H=reload)");
}