XInputGetKeystroke/Ex.

This commit is contained in:
Ben Vanik
2014-01-04 22:38:56 -08:00
parent 4d92720109
commit 9b02cfb560
9 changed files with 153 additions and 7 deletions

View File

@@ -32,6 +32,9 @@ public:
uint32_t user_index, X_INPUT_STATE& out_state) = 0;
virtual X_RESULT SetState(
uint32_t user_index, X_INPUT_VIBRATION& vibration) = 0;
virtual X_RESULT GetKeystroke(
uint32_t user_index, uint32_t flags,
X_INPUT_KEYSTROKE& out_keystroke) = 0;
protected:
InputDriver(InputSystem* input_system);

View File

@@ -23,7 +23,7 @@ InputSystem::InputSystem(Emulator* emulator) :
}
InputSystem::~InputSystem() {
for (std::vector<InputDriver*>::iterator it = drivers_.begin();
for (auto it = drivers_.begin();
it != drivers_.end(); ++it) {
InputDriver* driver = *it;
delete driver;
@@ -42,8 +42,7 @@ void InputSystem::AddDriver(InputDriver* driver) {
X_RESULT InputSystem::GetCapabilities(
uint32_t user_index, uint32_t flags, X_INPUT_CAPABILITIES& out_caps) {
for (std::vector<InputDriver*>::iterator it = drivers_.begin();
it != drivers_.end(); ++it) {
for (auto it = drivers_.begin(); it != drivers_.end(); ++it) {
InputDriver* driver = *it;
if (XSUCCEEDED(driver->GetCapabilities(user_index, flags, out_caps))) {
return X_ERROR_SUCCESS;
@@ -53,8 +52,7 @@ X_RESULT InputSystem::GetCapabilities(
}
X_RESULT InputSystem::GetState(uint32_t user_index, X_INPUT_STATE& out_state) {
for (std::vector<InputDriver*>::iterator it = drivers_.begin();
it != drivers_.end(); ++it) {
for (auto it = drivers_.begin(); it != drivers_.end(); ++it) {
InputDriver* driver = *it;
if (driver->GetState(user_index, out_state) == X_ERROR_SUCCESS) {
return X_ERROR_SUCCESS;
@@ -65,8 +63,7 @@ X_RESULT InputSystem::GetState(uint32_t user_index, X_INPUT_STATE& out_state) {
X_RESULT InputSystem::SetState(
uint32_t user_index, X_INPUT_VIBRATION& vibration) {
for (std::vector<InputDriver*>::iterator it = drivers_.begin();
it != drivers_.end(); ++it) {
for (auto it = drivers_.begin(); it != drivers_.end(); ++it) {
InputDriver* driver = *it;
if (XSUCCEEDED(driver->SetState(user_index, vibration))) {
return X_ERROR_SUCCESS;
@@ -74,3 +71,14 @@ X_RESULT InputSystem::SetState(
}
return X_ERROR_DEVICE_NOT_CONNECTED;
}
X_RESULT InputSystem::GetKeystroke(
uint32_t user_index, uint32_t flags, X_INPUT_KEYSTROKE& out_keystroke) {
for (auto it = drivers_.begin(); it != drivers_.end(); ++it) {
InputDriver* driver = *it;
if (XSUCCEEDED(driver->GetKeystroke(user_index, flags, out_keystroke))) {
return X_ERROR_SUCCESS;
}
}
return X_ERROR_DEVICE_NOT_CONNECTED;
}

View File

@@ -41,6 +41,8 @@ public:
uint32_t user_index, uint32_t flags, X_INPUT_CAPABILITIES& out_caps);
X_RESULT GetState(uint32_t user_index, X_INPUT_STATE& out_state);
X_RESULT SetState(uint32_t user_index, X_INPUT_VIBRATION& vibration);
X_RESULT GetKeystroke(uint32_t user_index, uint32_t flags,
X_INPUT_KEYSTROKE& out_keystroke);
private:
Emulator* emulator_;

View File

@@ -45,3 +45,8 @@ X_RESULT NopInputDriver::SetState(
uint32_t user_index, X_INPUT_VIBRATION& vibration) {
return X_ERROR_DEVICE_NOT_CONNECTED;
}
X_RESULT NopInputDriver::GetKeystroke(
uint32_t user_index, uint32_t flags, X_INPUT_KEYSTROKE& out_keystroke) {
return X_ERROR_DEVICE_NOT_CONNECTED;
}

View File

@@ -34,6 +34,8 @@ public:
uint32_t user_index, X_INPUT_STATE& out_state);
virtual X_RESULT SetState(
uint32_t user_index, X_INPUT_VIBRATION& vibration);
virtual X_RESULT GetKeystroke(
uint32_t user_index, uint32_t flags, X_INPUT_KEYSTROKE& out_keystroke);
protected:
};

View File

@@ -86,3 +86,22 @@ X_RESULT XInputInputDriver::SetState(
DWORD result = XInputSetState(user_index, &native_vibration);
return result;
}
X_RESULT XInputInputDriver::GetKeystroke(
uint32_t user_index, uint32_t flags, X_INPUT_KEYSTROKE& out_keystroke) {
// We may want to filter flags/user_index before sending to native.
// flags is reserved on desktop.
XINPUT_KEYSTROKE native_keystroke;
DWORD result = XInputGetKeystroke(user_index, flags, &native_keystroke);
if (result == ERROR_SUCCESS) {
out_keystroke.virtual_key = native_keystroke.VirtualKey;
out_keystroke.unicode = native_keystroke.Unicode;
out_keystroke.flags = native_keystroke.Flags;
out_keystroke.user_index = native_keystroke.UserIndex;
out_keystroke.hid_code = native_keystroke.HidCode;
}
// X_ERROR_EMPTY if no new keys
// X_ERROR_DEVICE_NOT_CONNECTED if no device
// X_ERROR_SUCCESS if key
return result;
}

View File

@@ -34,6 +34,8 @@ public:
uint32_t user_index, X_INPUT_STATE& out_state);
virtual X_RESULT SetState(
uint32_t user_index, X_INPUT_VIBRATION& vibration);
virtual X_RESULT GetKeystroke(
uint32_t user_index, uint32_t flags, X_INPUT_KEYSTROKE& out_keystroke);
protected:
};