Lib
QOLを高める
input.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "util.h"
4 #define DIRECTINPUT_VERSION 0x0800
5 #include <dinput.h>
6 #include <memory>
7 #include <array>
8 #include <vector>
9 
10 namespace yappy {
12 namespace input {
13 
16 class DInput : private util::noncopyable {
17 public:
19  static const int KEY_NUM = 256;
21  static const int AXIS_RANGE = 1000;
23  static const int AXIS_THRESHOLD = AXIS_RANGE / 2;
24 
28  using KeyData = std::array<bool, KEY_NUM>;
29 
36  DInput(HINSTANCE hInst, HWND hWnd, bool foreground = true, bool exclusive = false);
39  ~DInput();
40 
48  void updateControllers(HWND hwnd, bool foreground = true, bool exclusive = false);
52  void processFrame();
56  KeyData getKeys() const;
59  int getPadCount() const;
65  void getPadState(DIJOYSTATE *state, int index) const;
66 
67 private:
70  std::vector<DIDEVICEINSTANCE> m_padInstList;
71  std::vector<util::ComPtr<IDirectInputDevice8>> m_pPadDevs;
72  KeyData m_key;
73  std::vector<DIJOYSTATE> m_pad;
74 };
75 
77 const char *dikToString(int dik);
79 const wchar_t *dikToWString(int dik);
80 
81 } // namespace input
82 } // namespace yappy
int getPadCount() const
Get connected pad count.
Definition: input.cpp:182
Noncopyable class.
Definition: util.h:24
void updateControllers(HWND hwnd, bool foreground=true, bool exclusive=false)
Update pad list.
Definition: input.cpp:88
DInput(HINSTANCE hInst, HWND hWnd, bool foreground=true, bool exclusive=false)
Initialize DirectInput8.
Definition: input.cpp:15
~DInput()
Finalize DirectInput8.
Definition: input.cpp:52
const char * dikToString(int dik)
Convert DIK_XXX to string.
Definition: input.cpp:288
KeyData getKeys() const
Get keyboard input data.
Definition: input.cpp:177
Definition: config.cpp:6
static const int AXIS_THRESHOLD
Pad analog value threshold.
Definition: input.h:23
Utilities.
static const int KEY_NUM
Keyboard array count.
Definition: input.h:19
DirectInput8 wrapper.
Definition: input.h:16
void processFrame()
Must be called at every frame.
Definition: input.cpp:134
const wchar_t * dikToWString(int dik)
Convert DIK_XXX to wide-string.
Definition: input.cpp:296
std::array< bool, KEY_NUM > KeyData
Keyboard data: array[KEY_NUM] of bool.
Definition: input.h:28
void getPadState(DIJOYSTATE *state, int index) const
Get pad input data.
Definition: input.cpp:188
std::unique_ptr< T, ComDeleter > ComPtr
unique_ptr of IUnknown with ComDeleter.
Definition: util.h:88
static const int AXIS_RANGE
Pad analog value max.
Definition: input.h:21