2015-07-10 21:07:24 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2016-07-28 17:45:18 -04:00
|
|
|
#include <unordered_map>
|
2016-06-02 23:56:11 -04:00
|
|
|
#include "../Core/IKeyManager.h"
|
2016-07-16 16:25:57 -04:00
|
|
|
#include "../Utilities/Timer.h"
|
2018-06-09 15:42:27 -04:00
|
|
|
#include "../Utilities/AutoResetEvent.h"
|
2016-07-16 16:25:57 -04:00
|
|
|
#include "XInputManager.h"
|
|
|
|
#include "DirectInputManager.h"
|
2015-07-10 21:07:24 -04:00
|
|
|
|
|
|
|
struct KeyDefinition {
|
2015-07-11 08:27:22 -04:00
|
|
|
string name;
|
2015-07-10 21:07:24 -04:00
|
|
|
uint32_t keyCode;
|
2015-07-11 08:27:22 -04:00
|
|
|
string description;
|
2016-07-28 17:45:18 -04:00
|
|
|
string extDescription;
|
2015-07-10 21:07:24 -04:00
|
|
|
};
|
|
|
|
|
2018-07-01 15:21:05 -04:00
|
|
|
class Console;
|
|
|
|
|
2015-07-10 21:07:24 -04:00
|
|
|
class WindowsKeyManager : public IKeyManager
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
HWND _hWnd;
|
2018-07-01 15:21:05 -04:00
|
|
|
shared_ptr<Console> _console;
|
|
|
|
|
2016-12-14 18:26:52 -05:00
|
|
|
bool _keyState[0x200];
|
|
|
|
bool _mouseState[0x03];
|
2016-07-16 16:25:57 -04:00
|
|
|
unique_ptr<DirectInputManager> _directInput;
|
|
|
|
unique_ptr<XInputManager> _xInput;
|
2016-07-28 17:45:18 -04:00
|
|
|
std::unordered_map<uint32_t, string> _keyNames;
|
|
|
|
std::unordered_map<uint32_t, string> _keyExtendedNames;
|
|
|
|
std::unordered_map<string, uint32_t> _keyCodes;
|
2018-06-09 15:42:27 -04:00
|
|
|
|
|
|
|
AutoResetEvent _stopSignal;
|
2016-08-30 19:23:49 -04:00
|
|
|
|
|
|
|
std::thread _updateDeviceThread;
|
|
|
|
atomic<bool> _stopUpdateDeviceThread = false;
|
2017-09-08 10:38:41 -04:00
|
|
|
bool _disableAllKeys = false;
|
2016-08-30 19:23:49 -04:00
|
|
|
|
|
|
|
void StartUpdateDeviceThread();
|
2015-07-10 21:07:24 -04:00
|
|
|
|
|
|
|
public:
|
2018-07-01 15:21:05 -04:00
|
|
|
WindowsKeyManager(shared_ptr<Console> console, HWND hWnd);
|
2015-07-10 21:07:24 -04:00
|
|
|
~WindowsKeyManager();
|
|
|
|
|
|
|
|
void RefreshState();
|
|
|
|
bool IsKeyPressed(uint32_t key);
|
2016-02-14 12:58:35 -05:00
|
|
|
bool IsMouseButtonPressed(MouseButton button);
|
2017-09-08 10:38:41 -04:00
|
|
|
vector<uint32_t> GetPressedKeys();
|
2015-07-11 08:27:22 -04:00
|
|
|
string GetKeyName(uint32_t key);
|
|
|
|
uint32_t GetKeyCode(string keyName);
|
2016-07-16 16:25:57 -04:00
|
|
|
|
2016-07-28 17:45:18 -04:00
|
|
|
void SetKeyState(uint16_t scanCode, bool state);
|
|
|
|
void ResetKeyState();
|
2017-09-08 10:38:41 -04:00
|
|
|
void SetDisabled(bool disabled);
|
2016-07-28 17:45:18 -04:00
|
|
|
|
2016-07-16 16:25:57 -04:00
|
|
|
void UpdateDevices();
|
2015-07-10 21:07:24 -04:00
|
|
|
};
|