| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#pragma once |
| 5 |
|
| 6 |
#include <windows.h> |
| 7 |
|
| 8 |
#include "Common/Matrix.h" |
| 9 |
#include "InputCommon/ControllerInterface/ControllerInterface.h" |
| 10 |
#include "InputCommon/ControllerInterface/CoreDevice.h" |
| 11 |
#include "InputCommon/ControllerInterface/DInput/DInput8.h" |
| 12 |
|
| 13 |
namespace ciface::DInput |
| 14 |
{ |
| 15 |
void InitKeyboardMouse(IDirectInput8* const idi8, HWND hwnd); |
| 16 |
|
| 17 |
using RelativeMouseState = RelativeInputState<Common::TVec3<LONG>>; |
| 18 |
void SetKeyboardMouseWindow(HWND hwnd); |
| 19 |
|
| 20 |
class KeyboardMouse : public Core::Device |
| 21 |
{ |
| 22 |
private: |
| 23 |
struct State |
| 24 |
{ |
| 25 |
BYTE keyboard[256]{}; |
| 26 |
|
| 27 |
|
| 28 |
DIMOUSESTATE2 mouse{}; |
| 29 |
|
| 30 |
|
| 31 |
Common::TVec2<ControlState> cursor; |
| 32 |
|
| 33 |
|
| 34 |
RelativeMouseState relative_mouse; |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
class Key : public Input |
| 39 |
{ |
| 40 |
public: |
| 41 |
Key(u8 index, const BYTE& key) : m_key(key), m_index(index) {} |
| 42 |
std::string GetName() const override; |
| 43 |
ControlState GetState() const override; |
| 44 |
|
| 45 |
private: |
| 46 |
const BYTE& m_key; |
| 47 |
const u8 m_index; |
| 48 |
}; |
| 49 |
|
| 50 |
|
| 51 |
class Button : public Input |
| 52 |
{ |
| 53 |
public: |
| 54 |
Button(u8 index, const BYTE& button) : m_button(button), m_index(index) {} |
| 55 |
std::string GetName() const override; |
| 56 |
ControlState GetState() const override; |
| 57 |
|
| 58 |
private: |
| 59 |
const BYTE& m_button; |
| 60 |
const u8 m_index; |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
class Axis : public Input |
| 65 |
{ |
| 66 |
public: |
| 67 |
Axis(u8 index, const LONG& axis, LONG range) : m_axis(axis), m_range(range), m_index(index) {} |
| 68 |
std::string GetName() const override; |
| 69 |
bool IsDetectable() const override { return false; } |
| 70 |
ControlState GetState() const override; |
| 71 |
|
| 72 |
private: |
| 73 |
const LONG& m_axis; |
| 74 |
const LONG m_range; |
| 75 |
const u8 m_index; |
| 76 |
}; |
| 77 |
|
| 78 |
|
| 79 |
class Cursor : public Input |
| 80 |
{ |
| 81 |
public: |
| 82 |
Cursor(u8 index, const ControlState& axis, const bool positive) |
| 83 |
: m_axis(axis), m_index(index), m_positive(positive) |
| 84 |
{ |
| 85 |
} |
| 86 |
std::string GetName() const override; |
| 87 |
bool IsDetectable() const override { return false; } |
| 88 |
ControlState GetState() const override; |
| 89 |
|
| 90 |
private: |
| 91 |
const ControlState& m_axis; |
| 92 |
const u8 m_index; |
| 93 |
const bool m_positive; |
| 94 |
}; |
| 95 |
|
| 96 |
public: |
| 97 |
Core::DeviceRemoval UpdateInput() override; |
| 98 |
|
| 99 |
KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRECTINPUTDEVICE8 mo_device); |
| 100 |
~KeyboardMouse() override; |
| 101 |
|
| 102 |
std::string GetName() const override; |
| 103 |
std::string GetSource() const override; |
| 104 |
int GetSortPriority() const override; |
| 105 |
bool IsVirtualDevice() const override; |
| 106 |
|
| 107 |
private: |
| 108 |
void UpdateCursorInput(); |
| 109 |
|
| 110 |
const LPDIRECTINPUTDEVICE8 m_kb_device; |
| 111 |
const LPDIRECTINPUTDEVICE8 m_mo_device; |
| 112 |
|
| 113 |
DWORD m_last_update; |
| 114 |
State m_state_in; |
| 115 |
}; |
| 116 |
} |