Remove legacy keyboard events

** BREAKING CHANGE **

- Removed events:
    - KeyboardEvent
    - KeyDownEvent
    - KeyUpEvent
- Removed KeyBindingModule::Key::FromKeyboardEvent legacy KeyboardEvent overload
- Updated KeyboardGetDataEvent comments
This commit is contained in:
izawartka 2026-08-08 16:45:24 +02:00
parent 31b964f6ef
commit b7879d71eb
6 changed files with 3 additions and 139 deletions

View File

@ -567,7 +567,6 @@
<ClInclude Include="src\core\watch-manager.h" />
<ClInclude Include="src\core\watched-base.h" />
<ClInclude Include="src\events\game-tick.h" />
<ClInclude Include="src\events\keyboard.h" />
<ClInclude Include="src\game\common.h" />
<ClInclude Include="src\game\keycode.h" />
<ClInclude Include="src\game\functions.h" />
@ -654,7 +653,6 @@
<ClCompile Include="src\events\scale-shadow.cpp" />
<ClCompile Include="src\events\show-cursor.cpp" />
<ClCompile Include="src\events\try-shoot-weapon.cpp" />
<ClCompile Include="src\events\keyboard.cpp" />
<ClCompile Include="src\events\wsfix-z-update.cpp" />
<ClCompile Include="src\events\window-focus-change.cpp" />
<ClCompile Include="src\events\wnd-proc.cpp" />

View File

@ -23,7 +23,6 @@
<ClCompile Include="src\events\is-ammo-kf-call.cpp" />
<ClCompile Include="src\events\scale-shadow.cpp" />
<ClCompile Include="src\events\try-shoot-weapon.cpp" />
<ClCompile Include="src\events\keyboard.cpp" />
<ClCompile Include="src\game\keycode.cpp" />
<ClCompile Include="src\game\utils\car-roof-utils.cpp" />
<ClCompile Include="src\game\utils\player-utils.cpp" />
@ -369,7 +368,6 @@
<ClInclude Include="src\core\watch-manager.h" />
<ClInclude Include="src\core\watched-base.h" />
<ClInclude Include="src\events\game-tick.h" />
<ClInclude Include="src\events\keyboard.h" />
<ClInclude Include="src\game\common.h" />
<ClInclude Include="src\game\keycode.h" />
<ClInclude Include="src\game\functions.h" />

View File

@ -5,6 +5,8 @@
/*
Dispatched when the game is about to get keyboard data and can be used to emulate keyboard input.
One keyboard input per tick can be registered by the game, so check IsReadyToEmulate() before emulating a key.
Using priorities for emulated input is reccomended.
For simple OnKeyDown / OnKeyUp events use KeyboardModule.
*/
class KeyboardGetDataEvent : public Core::EventBase {
public:
@ -44,7 +46,7 @@ private:
};
/*
Dispatched after the game gets keyboard data.
Dispatched after KeyboardGetDataEvent, with the final data that is fed to the game.
Input that has been emulated using KeyboardGetDataEvent will also appear in this event.
*/
class PostKeyboardGetDataEvent : public Core::EventBase {

View File

@ -1,83 +0,0 @@
#include "keyboard.h"
#include "../hook-types/function-call-hook.h"
static bool isLeftShiftPressed = false;
static bool isLeftCtrlPressed = false;
static bool isLeftAltPressed = false;
static bool isRightShiftPressed = false;
static bool isRightCtrlPressed = false;
static bool isRightAltPressed = false;
static void UpdateModifierKeys(bool down, Game::KeyCode keyCode)
{
switch (keyCode)
{
case Game::KeyCode::DIK_LSHIFT:
isLeftShiftPressed = down;
break;
case Game::KeyCode::DIK_RSHIFT:
isRightShiftPressed = down;
break;
case Game::KeyCode::DIK_LCONTROL:
isLeftCtrlPressed = down;
break;
case Game::KeyCode::DIK_RCONTROL:
isRightCtrlPressed = down;
break;
case Game::KeyCode::DIK_LMENU:
isLeftAltPressed = down;
break;
case Game::KeyCode::DIK_RMENU:
isRightAltPressed = down;
break;
default:
break;
}
}
static void DispatchKeyboardEvent()
{
Game::KeyCode keyCode = *Game::Memory::GetKeyPressCode();
int keyState = *Game::Memory::GetKeyPressState();
bool isShiftPressed = isLeftShiftPressed || isRightShiftPressed;
bool isCtrlPressed = isLeftCtrlPressed || isRightCtrlPressed;
bool isAltPressed = isLeftAltPressed || isRightAltPressed;
if (keyState == 0) {
// Key up event
UpdateModifierKeys(false, keyCode);
KeyUpEvent event(keyCode, isShiftPressed, isCtrlPressed, isAltPressed);
Core::EventManager::GetInstance()->Dispatch(event);
}
else {
// Key down event
UpdateModifierKeys(true, keyCode);
KeyDownEvent event(keyCode, isShiftPressed, isCtrlPressed, isAltPressed);
Core::EventManager::GetInstance()->Dispatch(event);
}
}
static __declspec(naked) void OnKeyUpDownHookFunction(void)
{
__asm {
pushad
call DispatchKeyboardEvent
popad
jmp Game::Functions::OnKeyUpDown
}
}
const FunctionCallHook keyboardHook = {
0x0044c48d,
(DWORD)&OnKeyUpDownHookFunction
};
bool KeyDownEvent::Init()
{
return Core::HookManager::GetInstance()->AddHook(keyboardHook);
}
bool KeyUpEvent::Init()
{
return Core::HookManager::GetInstance()->AddHook(keyboardHook);
}

View File

@ -1,46 +0,0 @@
#pragma once
#include "../core/core.h"
#include "../game/game.h"
/*
Base class for all keyboard events. Not to be used directly.
*/
class KeyboardEvent : public Core::EventBase {
public:
static bool Init() { return false; }
Game::KeyCode GetKeyCode() const { return m_keyCode; }
bool IsShiftPressed() const { return m_shift; }
bool IsCtrlPressed() const { return m_ctrl; }
bool IsAltPressed() const { return m_alt; }
protected:
KeyboardEvent(Game::KeyCode keyCode, bool shift = false, bool ctrl = false, bool alt = false)
: m_keyCode(keyCode), m_shift(shift), m_ctrl(ctrl), m_alt(alt) {
};
virtual ~KeyboardEvent() override {};
Game::KeyCode m_keyCode;
bool m_shift = false;
bool m_ctrl = false;
bool m_alt = false;
};
/*
Dispatched when a key is pressed down.
*/
class KeyDownEvent : public KeyboardEvent {
public:
static bool Init();
KeyDownEvent(Game::KeyCode keyCode, bool shift = false, bool ctrl = false, bool alt = false)
: KeyboardEvent(keyCode, shift, ctrl, alt) { }
};
/*
Dispatched when a key is released.
*/
class KeyUpEvent : public KeyboardEvent {
public:
static bool Init();
KeyUpEvent(Game::KeyCode keyCode, bool shift = false, bool ctrl = false, bool alt = false)
: KeyboardEvent(keyCode, shift, ctrl, alt) { }
};

View File

@ -1,6 +1,5 @@
#pragma once
#include "common.h"
#include "../../events/keyboard.h"
namespace KeyBindingModule {
struct Key {
@ -15,10 +14,6 @@ namespace KeyBindingModule {
: keyCode(keyCode), shift(shift), ctrl(ctrl), alt(alt) {
}
static Key FromKeyboardEvent(const KeyboardEvent& event) {
return Key(event.GetKeyCode(), event.IsShiftPressed(), event.IsCtrlPressed(), event.IsAltPressed());
}
static Key FromKeyboardEvent(const KeyboardModule::KeyboardEventBase& event) {
return Key(event.GetKeyCode(), event.IsShiftPressed(), event.IsCtrlPressed(), event.IsAltPressed());
}