From b0faecd8a6822a386ecd2902fbbbd3a89b757084 Mon Sep 17 00:00:00 2001 From: Poke Date: Sun, 18 Oct 2015 11:31:34 +1030 Subject: [PATCH] Added 4 dir hat switch and more keys 4 Direction POV hat switch, and escape, control, alt as keys. --- PC/3DSController.ini | 4 ++-- PC/include/keys.h | 7 ++++++- PC/source/keys.c | 11 ++++++++++- PC/source/main.c | 3 +++ PC/source/settings.c | 8 ++++++++ 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/PC/3DSController.ini b/PC/3DSController.ini index 8c68bcf..05e3245 100644 --- a/PC/3DSController.ini +++ b/PC/3DSController.ini @@ -6,9 +6,9 @@ Circle Pad and C Stick may also be set to KEYS, which will enable Pad directions 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 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 JOY16). +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, WINDOWS, ESCAPE, CONTROL or ALT), a joypad button (JOY1, JOY2, JOY3, to JOY16) or vJoy Hat Switch direction (NORTH, EAST, SOUTH or WEST) (The hat switch must be enabled in vJoy Config. 4 way only, not continuous!) -If you want to use JOY9 through JOY16 you need to reconfigure vJoy. Search for vJoyConf in your start menu and set buttons to 16. +If you want to use JOY9 through JOY16 you need to reconfigure vJoy. Search for vJoy Config in your start menu and set buttons to 16. Alternatively, you can disable a key by binding it to NONE, diff --git a/PC/include/keys.h b/PC/include/keys.h index 7ba9136..7d12ca6 100644 --- a/PC/include/keys.h +++ b/PC/include/keys.h @@ -35,6 +35,10 @@ if(currentKeys & DSKey) joyButtons |= PCKey.joypadButton << 8;\ else joyButtons &= ~(PCKey.joypadButton << 8);\ }\ + else if(PCKey.useJoypad == 3) {\ + if(currentKeys & DSKey) hatButtons |= PCKey.joypadButton;\ + else hatButtons &= ~(PCKey.joypadButton);\ + }\ } while(0) #define BIT(n) (1 << (n)) @@ -72,7 +76,7 @@ typedef enum { } KEYPAD_BITS; struct keyMapping { - unsigned char useJoypad; // 0 keyboard key, 1 joypad1-8, 2 joypad9-16 + unsigned char useJoypad; // 0 keyboard key, 1 joypad1-8, 2 joypad9-16, 3 hat union { unsigned char virtualKey; unsigned char joypadButton; @@ -105,3 +109,4 @@ extern struct touch currentTouch; inline unsigned int mapVirtualKey(unsigned int key); void simulateKeyNewpress(unsigned int key); void simulateKeyRelease(unsigned int key); +void handleHat(unsigned int hat); diff --git a/PC/source/keys.c b/PC/source/keys.c index 8d7a89b..9e68c97 100644 --- a/PC/source/keys.c +++ b/PC/source/keys.c @@ -1,8 +1,9 @@ #include "keys.h" +#include "joystick.h" // Sideband comunication with vJoy Device //{781EF630-72B2-11d2-B852-00C04FAD5101} -DEFINE_GUID(GUID_DEVINTERFACE_VJOY, 0x781EF630, 0x72B2, 0x11d2, 0xB8, 0x52, 0x00, 0xC0, 0x4F, 0xAD, 0x51, 0x01); +//DEFINE_GUID(GUID_DEVINTERFACE_VJOY, 0x781EF630, 0x72B2, 0x11d2, 0xB8, 0x52, 0x00, 0xC0, 0x4F, 0xAD, 0x51, 0x01); unsigned int lastKeys; unsigned int currentKeys; @@ -76,3 +77,11 @@ void simulateKeyRelease(unsigned int key) { SendInput(1, &ip, sizeof(INPUT)); } + +void handleHat(unsigned int hat) { + if(hat & BIT(0)) iReport.bHats = 0; + else if(hat & BIT(1)) iReport.bHats = 1; + else if(hat & BIT(2)) iReport.bHats = 2; + else if(hat & BIT(3)) iReport.bHats = 3; + else iReport.bHats = -1; +} \ No newline at end of file diff --git a/PC/source/main.c b/PC/source/main.c index d78b6d4..2e8952e 100644 --- a/PC/source/main.c +++ b/PC/source/main.c @@ -28,6 +28,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) bool vJoy = true; UINT iInterface = settings.vJoyDevice; + int hatButtons = 0; iReport.wAxisX = JOY_MIDDLE; iReport.wAxisY = JOY_MIDDLE; @@ -136,6 +137,8 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) handleKey(KEY_X, settings.X); handleKey(KEY_Y, settings.Y); + handleHat(hatButtons); + if(settings.circlePad == keys) { handleKey(KEY_CPAD_RIGHT, settings.PadRight); handleKey(KEY_CPAD_LEFT, settings.PadLeft); diff --git a/PC/source/settings.c b/PC/source/settings.c index 82e6952..2a8298e 100644 --- a/PC/source/settings.c +++ b/PC/source/settings.c @@ -71,6 +71,9 @@ static struct keyMapping getButton(char *string) { 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, "ESCAPE") == 0) k.virtualKey = VK_ESCAPE; + else if(strcmp(string, "CONTROL") == 0) k.virtualKey = VK_CONTROL; + else if(strcmp(string, "ALT") == 0) k.virtualKey = VK_MENU; else if(strcmp(string, "NONE") == 0) k.virtualKey = 0; else if(strcmp(string, "JOY1") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 0; } @@ -90,6 +93,11 @@ static struct keyMapping getButton(char *string) { else if(strcmp(string, "JOY15") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 6; } else if(strcmp(string, "JOY16") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 7; } + else if(strcmp(string, "NORTH") == 0) { k.useJoypad = 3; k.joypadButton = 1 << 0; } + else if(strcmp(string, "EAST") == 0) { k.useJoypad = 3; k.joypadButton = 1 << 1; } + else if(strcmp(string, "SOUTH") == 0) { k.useJoypad = 3; k.joypadButton = 1 << 2; } + else if(strcmp(string, "WEST") == 0) { k.useJoypad = 3; k.joypadButton = 1 << 3; } + else k.virtualKey = (int)string[0]; return k;