Support joypad key mapping
This commit is contained in:
parent
038af67ecf
commit
2e72b1b0ff
7 changed files with 95 additions and 63 deletions
|
@ -4,7 +4,7 @@ Circle Pad and Touch can be either JOYSTICK or MOUSE,
|
|||
|
||||
Mouse Speed controls how fast the Circle Pad or Touch Screen moves the mouse. If set to 0 and using the Touch Screen, it will set to the absolute position, rather than moving relatively to last position,
|
||||
|
||||
Buttons can either be a letter for example B, or a special key, like SPACE, CLICK, RIGHT CLICK, ENTER, BACKSPACE, SHIFT, TAB, LEFT, RIGHT, UP, DOWN, PAGE UP, PAGE DOWN, or WINDOWS,
|
||||
Buttons can be a letter for a keyboard key (like Q, W, E, R, T, or Y), a special keyboard key (like SPACE, CLICK, RIGHT CLICK, ENTER, BACKSPACE, SHIFT, TAB, LEFT, RIGHT, UP, DOWN, PAGE UP, PAGE DOWN, or WINDOWS), or a joypad button (JOY1, JOY2, JOY3, to JOY8),
|
||||
|
||||
Alternatively, you can disable a key by binding it to NONE,
|
||||
|
||||
|
|
|
@ -9,10 +9,16 @@
|
|||
#include "public.h"
|
||||
#include "vjoyinterface.h"
|
||||
|
||||
#define joyX iReport.wAxisX
|
||||
#define joyY iReport.wAxisY
|
||||
#define joyButtons iReport.lButtons
|
||||
|
||||
#define JOY_MIDDLE (128 * 128)
|
||||
|
||||
extern int ContPovNumber;
|
||||
extern UINT iInterface;
|
||||
extern BOOL ContinuousPOV;
|
||||
//extern BOOL ContinuousPOV;
|
||||
|
||||
BOOL updateJoystick(int x, int y);
|
||||
extern JOYSTICK_POSITION iReport;
|
||||
|
||||
BOOL updateJoystick(void);
|
||||
|
|
|
@ -7,8 +7,16 @@
|
|||
#define newpress(key) ((currentKeys & key) && !(lastKeys & key))
|
||||
#define release(key) (!(currentKeys & key) && (lastKeys & key))
|
||||
|
||||
#define handleKey(DSKey, PCKey) if(newpress(DSKey)) simulateKeyNewpress(PCKey);\
|
||||
if(release(DSKey)) simulateKeyRelease(PCKey)
|
||||
#define handleKey(DSKey, PCKey) do {\
|
||||
if(PCKey.useKeyboard) {\
|
||||
if(newpress(DSKey)) simulateKeyNewpress(PCKey.virtualKey);\
|
||||
if(release(DSKey)) simulateKeyRelease(PCKey.virtualKey);\
|
||||
}\
|
||||
else {\
|
||||
if(currentKeys & DSKey) joyButtons |= PCKey.joypadButton;\
|
||||
else joyButtons &= ~PCKey.joypadButton;\
|
||||
}\
|
||||
} while(0)
|
||||
|
||||
#define BIT(n) (1 << (n))
|
||||
|
||||
|
@ -44,6 +52,14 @@ typedef enum {
|
|||
KEY_RIGHT = KEY_DRIGHT | KEY_CPAD_RIGHT,
|
||||
} KEYPAD_BITS;
|
||||
|
||||
struct keyMapping {
|
||||
unsigned char useKeyboard; // 0 joypad button, 1 keyboard key
|
||||
union {
|
||||
unsigned char virtualKey;
|
||||
unsigned char joypadButton;
|
||||
};
|
||||
};
|
||||
|
||||
struct circlePad {
|
||||
short x;
|
||||
short y;
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "keys.h"
|
||||
|
||||
enum analogue {
|
||||
mouse,
|
||||
joystick,
|
||||
|
@ -13,7 +15,7 @@ struct settings {
|
|||
enum analogue circlePad;
|
||||
enum analogue touch;
|
||||
int mouseSpeed;
|
||||
int A, B, X, Y, L, R, Left, Right, Up, Down, Start, Select, Tap;
|
||||
struct keyMapping A, B, X, Y, L, R, Left, Right, Up, Down, Start, Select, Tap;
|
||||
};
|
||||
|
||||
extern struct settings settings;
|
||||
|
|
|
@ -5,33 +5,15 @@
|
|||
|
||||
int ContPovNumber;
|
||||
UINT iInterface = 1;
|
||||
BOOL ContinuousPOV = FALSE;
|
||||
//BOOL ContinuousPOV = FALSE;
|
||||
|
||||
BOOL updateJoystick(int x, int y) {
|
||||
JOYSTICK_POSITION iReport;
|
||||
|
||||
BOOL updateJoystick(void) {
|
||||
BYTE id = (BYTE)iInterface;
|
||||
JOYSTICK_POSITION iReport;
|
||||
|
||||
iReport.bDevice = id;
|
||||
|
||||
iReport.wAxisX = x;
|
||||
iReport.wAxisY = y;
|
||||
iReport.wAxisZ = JOY_MIDDLE;
|
||||
iReport.wAxisXRot = JOY_MIDDLE;
|
||||
iReport.wAxisYRot = JOY_MIDDLE;
|
||||
iReport.wAxisZRot = JOY_MIDDLE;
|
||||
|
||||
iReport.lButtons = 0;
|
||||
|
||||
if(ContPovNumber) {
|
||||
iReport.bHats = -1; // Neutral state
|
||||
iReport.bHatsEx1 = -1; // Neutral state
|
||||
iReport.bHatsEx2 = -1; // Neutral state
|
||||
iReport.bHatsEx3 = -1; // Neutral state
|
||||
}
|
||||
else {
|
||||
iReport.bHats = -1; // Neutral state
|
||||
};
|
||||
|
||||
if(!UpdateVJD(iInterface, (PVOID)&iReport)) {
|
||||
/*printf("vJoy device %d failed - try to enable device\n", iInterface);
|
||||
printf("PRESS ENTER TO CONTINUE\n");
|
||||
|
|
|
@ -23,11 +23,19 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
|
|||
double widthMultiplier = screenWidth / 320.0;
|
||||
double heightMultiplier = screenHeight / 240.0;
|
||||
|
||||
screenshot(SCREENSHOT_NAMEL, TRUE, 0, 0, 18);
|
||||
//screenshot(SCREENSHOT_NAMEL, TRUE, 0, 0, 18);
|
||||
|
||||
bool vJoy = true;
|
||||
UINT iInterface = 1;
|
||||
|
||||
iReport.wAxisZ = JOY_MIDDLE;
|
||||
iReport.wAxisXRot = JOY_MIDDLE;
|
||||
iReport.wAxisYRot = JOY_MIDDLE;
|
||||
iReport.wAxisZRot = JOY_MIDDLE;
|
||||
iReport.wSlider = JOY_MIDDLE;
|
||||
iReport.lButtons = 0;
|
||||
iReport.bHats = -1;
|
||||
|
||||
if(vJoy && !vJoyEnabled()) {
|
||||
printf("vJoy failed (1)! Buttons will still work, but joy stick won't work.\n");
|
||||
vJoy = false;
|
||||
|
@ -42,8 +50,8 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
|
|||
ContPovNumber = GetVJDContPovNumber(iInterface);
|
||||
//int DiscPovNumber = GetVJDDiscPovNumber(iInterface);
|
||||
|
||||
if(vJoy && !updateJoystick(128 * 128, 128 * 128)) {
|
||||
printf("vJoy failed (3)! Buttons will still work, but joy stick won't work.\n");
|
||||
if(vJoy && !updateJoystick()) {
|
||||
printf("vJoy failed (3)! Buttons will still work, but joystick won't work.\n");
|
||||
vJoy = false;
|
||||
}
|
||||
|
||||
|
@ -148,7 +156,8 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
|
|||
}
|
||||
}
|
||||
else if(settings.touch == joystick) {
|
||||
if(vJoy) updateJoystick((currentTouch.x) * 128, (currentTouch.y) * 128);
|
||||
joyX = (currentTouch.x) * 128;
|
||||
joyY = (currentTouch.y) * 128;
|
||||
}
|
||||
else {
|
||||
handleKey(KEY_TOUCH, settings.Tap);
|
||||
|
@ -164,12 +173,15 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
|
|||
SetCursorPos(p.x + (circlePad.x * settings.mouseSpeed) / 32, p.y - (circlePad.y * settings.mouseSpeed) / 32);
|
||||
}
|
||||
else if(settings.circlePad == joystick) {
|
||||
if(vJoy) updateJoystick((circlePad.x + 128) * 128, (128 - circlePad.y) * 128);
|
||||
joyX = (circlePad.x + 128) * 128;
|
||||
joyY = (128 - circlePad.y) * 128;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(vJoy) updateJoystick();
|
||||
|
||||
//sendScreenshot();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <string.h>
|
||||
#include <windows.h>
|
||||
|
||||
#include "keys.h"
|
||||
#include "wireless.h"
|
||||
|
||||
#include "settings.h"
|
||||
|
@ -14,19 +15,19 @@ struct settings defaultSettings = {
|
|||
circlePad: joystick,
|
||||
touch: mouse,
|
||||
mouseSpeed: 4,
|
||||
A: 'A',
|
||||
B: 'B',
|
||||
X: 'X',
|
||||
Y: 'Y',
|
||||
L: 'L',
|
||||
R: 'R',
|
||||
Left: VK_LEFT,
|
||||
Right: VK_RIGHT,
|
||||
Up: VK_UP,
|
||||
Down: VK_DOWN,
|
||||
Start: VK_RETURN,
|
||||
Select: VK_BACK,
|
||||
Tap: 'T',
|
||||
A: { 1, {'A'} },
|
||||
B: { 1, {'B'} },
|
||||
X: { 1, {'X'} },
|
||||
Y: { 1, {'Y'} },
|
||||
L: { 1, {'L'} },
|
||||
R: { 1, {'R'} },
|
||||
Left: { 1, {VK_LEFT} },
|
||||
Right: { 1, {VK_RIGHT} },
|
||||
Up: { 1, {VK_UP} },
|
||||
Down: { 1, {VK_DOWN} },
|
||||
Start: { 1, {VK_RETURN} },
|
||||
Select: { 1, {VK_BACK} },
|
||||
Tap: { 1, {'T'} },
|
||||
};
|
||||
|
||||
static bool getSetting(char *name, char *src, char *dest) {
|
||||
|
@ -48,24 +49,37 @@ static bool getSetting(char *name, char *src, char *dest) {
|
|||
return false;
|
||||
}
|
||||
|
||||
static int getButton(char *string) {
|
||||
if(strcmp(string, "SPACE") == 0) return VK_SPACE;
|
||||
else if(strcmp(string, "CLICK") == 0) return VK_LBUTTON;
|
||||
else if(strcmp(string, "RIGHT CLICK") == 0) return VK_RBUTTON;
|
||||
else if(strcmp(string, "ENTER") == 0) return VK_RETURN;
|
||||
else if(strcmp(string, "BACKSPACE") == 0) return VK_BACK;
|
||||
else if(strcmp(string, "SHIFT") == 0) return VK_SHIFT;
|
||||
else if(strcmp(string, "TAB") == 0) return VK_TAB;
|
||||
else if(strcmp(string, "LEFT") == 0) return VK_LEFT;
|
||||
else if(strcmp(string, "RIGHT") == 0) return VK_RIGHT;
|
||||
else if(strcmp(string, "UP") == 0) return VK_UP;
|
||||
else if(strcmp(string, "DOWN") == 0) return VK_DOWN;
|
||||
else if(strcmp(string, "PAGE UP") == 0) return VK_PRIOR;
|
||||
else if(strcmp(string, "PAGE DOWN") == 0) return VK_NEXT;
|
||||
else if(strcmp(string, "WINDOWS") == 0) return VK_LWIN;
|
||||
else if(strcmp(string, "NONE") == 0) return 0;
|
||||
static struct keyMapping getButton(char *string) {
|
||||
struct keyMapping k = { 1, {0} };
|
||||
|
||||
return (int)string[0];
|
||||
if(strcmp(string, "SPACE") == 0) k.virtualKey = VK_SPACE;
|
||||
else if(strcmp(string, "CLICK") == 0) k.virtualKey = VK_LBUTTON;
|
||||
else if(strcmp(string, "RIGHT CLICK") == 0) k.virtualKey = VK_RBUTTON;
|
||||
else if(strcmp(string, "ENTER") == 0) k.virtualKey = VK_RETURN;
|
||||
else if(strcmp(string, "BACKSPACE") == 0) k.virtualKey = VK_BACK;
|
||||
else if(strcmp(string, "SHIFT") == 0) k.virtualKey = VK_SHIFT;
|
||||
else if(strcmp(string, "TAB") == 0) k.virtualKey = VK_TAB;
|
||||
else if(strcmp(string, "LEFT") == 0) k.virtualKey = VK_LEFT;
|
||||
else if(strcmp(string, "RIGHT") == 0) k.virtualKey = VK_RIGHT;
|
||||
else if(strcmp(string, "UP") == 0) k.virtualKey = VK_UP;
|
||||
else if(strcmp(string, "DOWN") == 0) k.virtualKey = VK_DOWN;
|
||||
else if(strcmp(string, "PAGE UP") == 0) k.virtualKey = VK_PRIOR;
|
||||
else if(strcmp(string, "PAGE DOWN") == 0) k.virtualKey = VK_NEXT;
|
||||
else if(strcmp(string, "WINDOWS") == 0) k.virtualKey = VK_LWIN;
|
||||
else if(strcmp(string, "NONE") == 0) k.virtualKey = 0;
|
||||
|
||||
else if(strcmp(string, "JOY1") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 0; }
|
||||
else if(strcmp(string, "JOY2") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 1; }
|
||||
else if(strcmp(string, "JOY3") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 2; }
|
||||
else if(strcmp(string, "JOY4") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 3; }
|
||||
else if(strcmp(string, "JOY5") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 4; }
|
||||
else if(strcmp(string, "JOY6") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 5; }
|
||||
else if(strcmp(string, "JOY7") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 6; }
|
||||
else if(strcmp(string, "JOY8") == 0) { k.useKeyboard = 0; k.joypadButton = 1 << 7; }
|
||||
|
||||
else k.virtualKey = (int)string[0];
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
bool readSettings(void) {
|
||||
|
|
Loading…
Reference in a new issue