Add mechanism for unlimited mappable virtual keys (not restricted by some bitfield). Use it to implement X/Y analog key mapping.

This commit is contained in:
Henrik Rydgard committed 2013-07-06 20:45:44 +02:00
1 parent cc58e34cf8
commit b0ee3a173a
8 files changed
+197 -82

No files matched your search

+3 -43
View File
@@ -10,7 +10,8 @@
#include "../Core/HLE/sceCtrl.h"
#include "WinUser.h"
unsigned int key_pad_map[] = {
// TODO: remove. almost not used.
static unsigned int key_pad_map[] = {
VK_ESCAPE,PAD_BUTTON_MENU, // Open PauseScreen
VK_BACK, PAD_BUTTON_BACK, // Toggle PauseScreen & Back Setting Page
'Z', PAD_BUTTON_A,
@@ -31,13 +32,6 @@ unsigned int key_pad_map[] = {
const unsigned int key_pad_map_size = sizeof(key_pad_map);
unsigned short analog_ctrl_map[] = {
'I', CTRL_UP,
'K', CTRL_DOWN,
'J', CTRL_LEFT,
'L', CTRL_RIGHT,
};
// TODO: More keys need to be added, but this is more than
// a fair start.
std::map<int, int> windowsTransTable = InitConstMap<int, int>
@@ -121,8 +115,6 @@ std::map<int, int> windowsTransTable = InitConstMap<int, int>
(VK_OEM_6, KEYCODE_RIGHT_BRACKET)
(VK_MENU, KEYCODE_MENU);
const unsigned int analog_ctrl_map_size = sizeof(analog_ctrl_map);
int KeyboardDevice::UpdateState(InputState &input_state) {
if (MainWindow::GetHWND() != GetForegroundWindow()) return -1;
bool alternate = GetAsyncKeyState(VK_SHIFT) != 0;
@@ -135,13 +127,13 @@ int KeyboardDevice::UpdateState(InputState &input_state) {
input_state.pad_buttons |= PAD_BUTTON_UNTHROTTLE;
}
// TODO: remove
for (int i = 0; i < sizeof(key_pad_map)/sizeof(key_pad_map[0]); i += 2) {
if (!GetAsyncKeyState(key_pad_map[i])) {
continue;
}
if (!doAlternate || key_pad_map[i + 1] > PAD_BUTTON_SELECT) {
// TODO: remove once EmuScreen supports virtual keys
switch (key_pad_map[i + 1]) {
case PAD_BUTTON_MENU:
case PAD_BUTTON_BACK:
@@ -172,38 +164,6 @@ int KeyboardDevice::UpdateState(InputState &input_state) {
}
upKeys.clear();
// TODO: Better axis mapping
float analogX = 0;
float analogY = 0;
for (int i = 0; i < sizeof(analog_ctrl_map)/sizeof(analog_ctrl_map[0]); i += 2) {
if (!GetAsyncKeyState(analog_ctrl_map[i])) {
continue;
}
switch (analog_ctrl_map[i + 1]) {
case CTRL_UP:
analogY += 1.0f;
break;
case CTRL_DOWN:
analogY -= 1.0f;
break;
case CTRL_LEFT:
analogX -= 1.0f;
break;
case CTRL_RIGHT:
analogX += 1.0f;
break;
}
}
AxisInput axis;
axis.deviceId = DEVICE_ID_KEYBOARD;
axis.axisId = JOYSTICK_AXIS_X;
axis.value = analogX;
NativeAxis(axis);
axis.axisId = JOYSTICK_AXIS_Y;
axis.value = analogY;
NativeAxis(axis);
return 0;
}