DInputKeyboardMouse.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright 2010 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <windows.h>
  5. #include "Common/Matrix.h"
  6. #include "InputCommon/ControllerInterface/ControllerInterface.h"
  7. #include "InputCommon/ControllerInterface/CoreDevice.h"
  8. #include "InputCommon/ControllerInterface/DInput/DInput8.h"
  9. namespace ciface::DInput
  10. {
  11. void InitKeyboardMouse(IDirectInput8* const idi8, HWND hwnd);
  12. using RelativeMouseState = RelativeInputState<Common::TVec3<LONG>>;
  13. void SetKeyboardMouseWindow(HWND hwnd);
  14. class KeyboardMouse : public Core::Device
  15. {
  16. private:
  17. struct State
  18. {
  19. BYTE keyboard[256]{};
  20. // Old smoothed relative mouse movement.
  21. DIMOUSESTATE2 mouse{};
  22. // Normalized mouse cursor position.
  23. Common::TVec2<ControlState> cursor;
  24. // Raw relative mouse movement.
  25. RelativeMouseState relative_mouse;
  26. };
  27. // Keyboard key
  28. class Key : public Input
  29. {
  30. public:
  31. Key(u8 index, const BYTE& key) : m_key(key), m_index(index) {}
  32. std::string GetName() const override;
  33. ControlState GetState() const override;
  34. private:
  35. const BYTE& m_key;
  36. const u8 m_index;
  37. };
  38. // Mouse button
  39. class Button : public Input
  40. {
  41. public:
  42. Button(u8 index, const BYTE& button) : m_button(button), m_index(index) {}
  43. std::string GetName() const override;
  44. ControlState GetState() const override;
  45. private:
  46. const BYTE& m_button;
  47. const u8 m_index;
  48. };
  49. // Mouse movement offset axis. Includes mouse wheel
  50. class Axis : public Input
  51. {
  52. public:
  53. Axis(u8 index, const LONG& axis, LONG range) : m_axis(axis), m_range(range), m_index(index) {}
  54. std::string GetName() const override;
  55. bool IsDetectable() const override { return false; }
  56. ControlState GetState() const override;
  57. private:
  58. const LONG& m_axis;
  59. const LONG m_range;
  60. const u8 m_index;
  61. };
  62. // Mouse from window center
  63. class Cursor : public Input
  64. {
  65. public:
  66. Cursor(u8 index, const ControlState& axis, const bool positive)
  67. : m_axis(axis), m_index(index), m_positive(positive)
  68. {
  69. }
  70. std::string GetName() const override;
  71. bool IsDetectable() const override { return false; }
  72. ControlState GetState() const override;
  73. private:
  74. const ControlState& m_axis;
  75. const u8 m_index;
  76. const bool m_positive;
  77. };
  78. public:
  79. Core::DeviceRemoval UpdateInput() override;
  80. KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRECTINPUTDEVICE8 mo_device);
  81. ~KeyboardMouse();
  82. std::string GetName() const override;
  83. std::string GetSource() const override;
  84. int GetSortPriority() const override;
  85. bool IsVirtualDevice() const override;
  86. private:
  87. void UpdateCursorInput();
  88. const LPDIRECTINPUTDEVICE8 m_kb_device;
  89. const LPDIRECTINPUTDEVICE8 m_mo_device;
  90. DWORD m_last_update;
  91. State m_state_in;
  92. };
  93. } // namespace ciface::DInput