Skip to content

Commit 9dd89e8

Browse files
committed
Improvements: left stick modes, screenshot modes and fixes
1 parent 0cfd507 commit 9dd89e8

File tree

2 files changed

+90
-16
lines changed

2 files changed

+90
-16
lines changed

Source/DSAdvance/DSAdvance.cpp

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@ void LoadKMProfile(std::string ProfileFile) {
379379
ButtonsStates.Back.KeyCode = KeyNameToKeyCode(IniFile.ReadString("GAMEPAD", "BACK", "ESCAPE"));
380380
ButtonsStates.Start.KeyCode = KeyNameToKeyCode(IniFile.ReadString("GAMEPAD", "START", "ENTER"));
381381

382-
ButtonsStates.DPADUp.KeyCode = KeyNameToKeyCode(IniFile.ReadString("GAMEPAD", "DPAD-UP", "1"));
383-
ButtonsStates.DPADDown.KeyCode = KeyNameToKeyCode(IniFile.ReadString("GAMEPAD", "DPAD-DOWN", "4"));
384-
ButtonsStates.DPADLeft.KeyCode = KeyNameToKeyCode(IniFile.ReadString("GAMEPAD", "DPAD-LEFT", "2"));
382+
ButtonsStates.DPADUp.KeyCode = KeyNameToKeyCode(IniFile.ReadString("GAMEPAD", "DPAD-UP", "2"));
383+
ButtonsStates.DPADLeft.KeyCode = KeyNameToKeyCode(IniFile.ReadString("GAMEPAD", "DPAD-LEFT", "1"));
385384
ButtonsStates.DPADRight.KeyCode = KeyNameToKeyCode(IniFile.ReadString("GAMEPAD", "DPAD-RIGHT", "3"));
385+
ButtonsStates.DPADDown.KeyCode = KeyNameToKeyCode(IniFile.ReadString("GAMEPAD", "DPAD-DOWN", "4"));
386386

387387
ButtonsStates.Y.KeyCode = KeyNameToKeyCode(IniFile.ReadString("GAMEPAD", "TRIANGLE-Y", "E"));
388388
ButtonsStates.X.KeyCode = KeyNameToKeyCode(IniFile.ReadString("GAMEPAD", "SQUARE-X", "R"));
@@ -422,7 +422,7 @@ void MainTextUpdate() {
422422
else if (AppStatus.GamepadEmulationMode == EmuGamepadDisabled)
423423
printf(" Emulation: Only mouse (for mouse aiming).\n");
424424
else if (AppStatus.GamepadEmulationMode == EmuKeyboardAndMouse)
425-
printf_s(" Emulation: Keyboard and mouse - %s.\n Change profiles with \"ALT + Up | Down\" or \"PS + DPAD Up | Down\".\n", KMProfiles[ProfileIndex].c_str());
425+
printf_s(" Emulation: Keyboard and mouse (%s).\n Change profiles with \"ALT + Up | Down\" or \"PS + DPAD Up | Down\".\n", KMProfiles[ProfileIndex].c_str());
426426
printf(" Press \"ALT + Q\" or \"PS + DPAD Left | Right\" to switch emulation.\n");
427427

428428
if (AppStatus.ExternalPedalsConnected)
@@ -431,17 +431,37 @@ void MainTextUpdate() {
431431
if (AppStatus.AimMode == AimMouseMode) printf(" AIM mode = mouse"); else printf(" AIM mode = mouse-joystick");
432432
printf(", press \"ALT + A\" or \"PS + R1\" to switch.\n");
433433

434+
if (AppStatus.GamepadEmulationMode == EmuGamepadEnabled) {
435+
if (AppStatus.LeftStickMode == LeftStickDefaultMode)
436+
printf(" Left stick mode: Default");
437+
else if (AppStatus.LeftStickMode == LeftStickAutoPressMode)
438+
printf(" Left stick mode: Auto pressing by value");
439+
else if (AppStatus.LeftStickMode == LeftStickInvertPressMode)
440+
printf(" Left stick mode: Invert pressed");
441+
printf(", press \"ALT + S\" or \"PS + LS\" to switch.\n");
442+
}
443+
434444
if (AppStatus.ChangeModesWithoutPress) printf(" Change modes without pressing the touchpad"); else printf(" Change modes by pressing the touchpad");
435445
printf(", press \"ALT + W\" or \"PS + Share\" to switch.\n");
436446
printf(" Press \"ALT + B\" or \"PS + L1\" to turn the backlight on or off.\n");
437447

448+
if (AppStatus.ScreenshotMode == ScreenShotCustomKeyMode)
449+
printf(" Screenshot mode: Custom key");
450+
else if (AppStatus.ScreenshotMode == ScreenShotXboxGameBarMode)
451+
printf(" Screenshot mode: Xbox Game Bar");
452+
else if (AppStatus.ScreenshotMode == ScreenShotSteamMode)
453+
printf(" Screenshot mode: Steam (F12)");
454+
else if (AppStatus.ScreenshotMode == ScreenShotMultiMode)
455+
printf(" Screenshot mode: Xbox Game Bar & Steam (F12)");
456+
printf(", press \"ALT + X\" to switch.\n");
457+
438458
printf(" Press \"ALT + F9\" to get the sticks dead zones.\n");
439459
printf(" Press \"ALT + Escape\" to exit.\n");
440460
}
441461

442462
int main(int argc, char **argv)
443463
{
444-
SetConsoleTitle("DSAdvance 0.8.5");
464+
SetConsoleTitle("DSAdvance 0.8.6");
445465
// Config parameters
446466
CIniReader IniFile("Config.ini");
447467

@@ -465,6 +485,8 @@ int main(int argc, char **argv)
465485
float TouchRightStickX = IniFile.ReadFloat("Gamepad", "TouchRightStickSensX", 4);
466486
float TouchRightStickY = IniFile.ReadFloat("Gamepad", "TouchRightStickSensY", 4);
467487

488+
float AutoPressModeValue = IniFile.ReadFloat("Gamepad", "AutoPressModeStick", 99) * 0.01f;
489+
468490
unsigned char DefaultLEDBrightness = std::clamp((int)(255 - IniFile.ReadInteger("Gamepad", "DefaultBrightness", 100) * 2.55), 0, 255);
469491
bool LockedChangeBrightness = IniFile.ReadBoolean("Gamepad", "LockChangeBrightness", false);
470492
bool LockChangeBrightness = true;
@@ -482,7 +504,11 @@ int main(int argc, char **argv)
482504
float JoySensY = IniFile.ReadFloat("Motion", "JoySensY", 3);
483505
float CustomMulSens = 1;
484506

507+
int ScreenShotKey = VK_GAMEBAR_SCREENSHOT;
485508
int MicCustomKey = KeyNameToKeyCode(IniFile.ReadString("Gamepad", "MicCustomKey", "NONE"));
509+
if (MicCustomKey == 0) AppStatus.ScreenshotMode = ScreenShotXboxGameBarMode; // If not set, then hide this mode
510+
else ScreenShotKey = MicCustomKey;
511+
486512

487513
int ExternalPedalsCOMPort = IniFile.ReadInteger("ExternalPedals", "COMPort", 0);
488514
if (ExternalPedalsCOMPort != 0) {
@@ -630,7 +656,7 @@ int main(int argc, char **argv)
630656
}
631657
}
632658

633-
SkipPollCount = 35; // 15 is seems not enough to enable or disable Xbox virtual gamepad
659+
SkipPollCount = 30; // 15 is seems not enough to enable or disable Xbox virtual gamepad
634660

635661
if (AppStatus.GamepadEmulationMode == EmuKeyboardAndMouse)
636662
LoadKMProfile(KMProfiles[ProfileIndex]);
@@ -658,6 +684,26 @@ int main(int argc, char **argv)
658684
SkipPollCount = SkipPollTimeOut;
659685
}
660686

687+
// Switch left stick mode
688+
if ((((GetAsyncKeyState(VK_MENU) & 0x8000) != 0 && (GetAsyncKeyState('S') & 0x8000) != 0) || (InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_LCLICK)) && SkipPollCount == 0)
689+
{
690+
AppStatus.LeftStickMode++; if (AppStatus.LeftStickMode > LeftStickMaxModes) AppStatus.LeftStickMode = LeftStickDefaultMode;
691+
MainTextUpdate();
692+
SkipPollCount = SkipPollTimeOut;
693+
}
694+
695+
// Switch screenshot mode
696+
if ((GetAsyncKeyState(VK_MENU) & 0x8000) != 0 && (GetAsyncKeyState('X') & 0x8000) != 0 && SkipPollCount == 0)
697+
{
698+
AppStatus.ScreenshotMode++; if (AppStatus.ScreenshotMode > ScreenShotMaxModes) AppStatus.ScreenshotMode = MicCustomKey == 0 ? ScreenShotXboxGameBarMode : ScreenShotCustomKeyMode;
699+
if (AppStatus.ScreenshotMode == ScreenShotCustomKeyMode) ScreenShotKey = MicCustomKey;
700+
else if (AppStatus.ScreenshotMode == ScreenShotXboxGameBarMode) ScreenShotKey = VK_GAMEBAR_SCREENSHOT;
701+
else if (AppStatus.ScreenshotMode == ScreenShotSteamMode) ScreenShotKey = VK_STEAM_SCREENSHOT;
702+
else if (AppStatus.ScreenshotMode == ScreenShotMultiMode) ScreenShotKey = VK_MULTI_SCREENSHOT;
703+
MainTextUpdate();
704+
SkipPollCount = SkipPollTimeOut;
705+
}
706+
661707
// Enable or disable lightbar
662708
if ((((GetAsyncKeyState(VK_MENU) & 0x8000) != 0 && (GetAsyncKeyState('B') & 0x8000) != 0) || (InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_L)) && SkipPollCount == 0)
663709
{
@@ -762,6 +808,10 @@ int main(int argc, char **argv)
762808
report.sThumbRX = InvertRightStickX == false ? DeadZoneAxis(InputState.stickRX, DeadZoneRightStickX) * 32767 : DeadZoneAxis(-InputState.stickRX, DeadZoneRightStickX) * 32767;
763809
report.sThumbRY = InvertRightStickY == false ? DeadZoneAxis(InputState.stickRY, DeadZoneRightStickY) * 32767 : DeadZoneAxis(-InputState.stickRY, DeadZoneRightStickY) * 32767;
764810

811+
// Auto stick pressing when value is exceeded
812+
if (AppStatus.LeftStickMode == LeftStickAutoPressMode && (abs(InputState.stickLX) > AutoPressModeValue || abs(InputState.stickLY) > AutoPressModeValue))
813+
report.wButtons |= JSMASK_LCLICK;
814+
765815
report.bLeftTrigger = InputState.lTrigger * 255;
766816
report.bRightTrigger = InputState.rTrigger * 255;
767817

@@ -784,8 +834,11 @@ int main(int argc, char **argv)
784834

785835
if (!(InputState.buttons & JSMASK_PS)) { // During special functions, nothing is pressed in the game
786836
report.wButtons |= InputState.buttons & JSMASK_L ? XINPUT_GAMEPAD_LEFT_SHOULDER : 0;
787-
report.wButtons |= InputState.buttons & JSMASK_R ? XINPUT_GAMEPAD_RIGHT_SHOULDER : 0;
788-
report.wButtons |= InputState.buttons & JSMASK_LCLICK ? XINPUT_GAMEPAD_LEFT_THUMB : 0;
837+
report.wButtons |= InputState.buttons & JSMASK_R ? XINPUT_GAMEPAD_RIGHT_SHOULDER : 0;
838+
if (AppStatus.LeftStickMode != LeftStickInvertPressMode) // Invert stick mode
839+
report.wButtons |= InputState.buttons & JSMASK_LCLICK ? XINPUT_GAMEPAD_LEFT_THUMB : 0;
840+
else
841+
report.wButtons |= InputState.buttons & JSMASK_LCLICK ? 0 : XINPUT_GAMEPAD_LEFT_THUMB;
789842
report.wButtons |= InputState.buttons & JSMASK_RCLICK ? XINPUT_GAMEPAD_RIGHT_THUMB : 0;
790843
report.wButtons |= InputState.buttons & JSMASK_UP ? XINPUT_GAMEPAD_DPAD_UP : 0;
791844
report.wButtons |= InputState.buttons & JSMASK_DOWN ? XINPUT_GAMEPAD_DPAD_DOWN : 0;
@@ -818,7 +871,7 @@ int main(int argc, char **argv)
818871
KeyPress(VK_GAMEBAR, PSOnlyCheckCount == 1 && PSOnlyPressed, &ButtonsStates.PS);
819872
KeyPress(VK_VOLUME_DOWN, InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_W, &ButtonsStates.VolumeDown);
820873
KeyPress(VK_VOLUME_UP, InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_E, &ButtonsStates.VolumeUP);
821-
KeyPress(MicCustomKey == 0 ? VK_GAMEBAR_SCREENSHOT : MicCustomKey, InputState.buttons & JSMASK_MIC || (InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_S), &ButtonsStates.Mic); // + DualShock 4
874+
KeyPress(ScreenShotKey, InputState.buttons & JSMASK_MIC || (InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_S), &ButtonsStates.Mic); // + DualShock 4
822875

823876
// Custom sens
824877
if (InputState.buttons & JSMASK_PS && InputState.buttons & JSMASK_N && SkipPollCount == 0) {

Source/DSAdvance/DSAdvance.h

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@
5555
#define MotionAimingModeOnlyPressed 3
5656
#define TouchpadSticksMode 4
5757

58+
#define LeftStickDefaultMode 0
59+
#define LeftStickAutoPressMode 1
60+
#define LeftStickInvertPressMode 2
61+
#define LeftStickMaxModes 2
62+
63+
#define ScreenShotCustomKeyMode 0
64+
#define ScreenShotXboxGameBarMode 1
65+
#define ScreenShotSteamMode 2
66+
#define ScreenShotMultiMode 3
67+
#define ScreenShotMaxModes 3
68+
5869
#define SkipPollTimeOut 15
5970
#define ResetControllersTimeOut 2000 // JoyShockLibrary bug with increase in CPU usage when the controller is turned off & auto connection gamepad
6071
#define PSReleasedTimeOut 30
@@ -81,9 +92,11 @@
8192
#define VK_DISPLAY_KEYBOARD 508
8293
#define VK_GAMEBAR 509
8394
#define VK_GAMEBAR_SCREENSHOT 510
84-
#define VK_FULLSCREEN 511
85-
#define VK_FULLSCREEN_PLUS 512
86-
#define VK_CHANGE_LANGUAGE 513
95+
#define VK_STEAM_SCREENSHOT 511
96+
#define VK_MULTI_SCREENSHOT 512
97+
#define VK_FULLSCREEN 513
98+
#define VK_FULLSCREEN_PLUS 514
99+
#define VK_CHANGE_LANGUAGE 515
87100

88101

89102
bool ExternalPedalsConnected = false;
@@ -248,11 +261,14 @@ void KeyPress(int KeyCode, bool ButtonPressed, Button* ButtonState) {
248261
keybd_event(VK_LWIN, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
249262
keybd_event('G', 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
250263

251-
} else if (KeyCode == VK_GAMEBAR_SCREENSHOT) {
264+
} else if (KeyCode == VK_GAMEBAR_SCREENSHOT || KeyCode == VK_MULTI_SCREENSHOT) {
252265
keybd_event(VK_LWIN, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
253266
keybd_event(VK_MENU, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
254267
keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
255268

269+
} else if (KeyCode == VK_STEAM_SCREENSHOT) {
270+
keybd_event(VK_F12, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
271+
256272
} else if (KeyCode == VK_FULLSCREEN || KeyCode == VK_FULLSCREEN_PLUS) {
257273
keybd_event(VK_MENU, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
258274
keybd_event(VK_RETURN, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
@@ -288,10 +304,14 @@ void KeyPress(int KeyCode, bool ButtonPressed, Button* ButtonState) {
288304
keybd_event('G', 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
289305
keybd_event(VK_LWIN, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
290306

291-
} else if (KeyCode == VK_GAMEBAR_SCREENSHOT) {
307+
} else if (KeyCode == VK_GAMEBAR_SCREENSHOT || (KeyCode == VK_MULTI_SCREENSHOT)) {
292308
keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
293309
keybd_event(VK_MENU, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
294310
keybd_event(VK_LWIN, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
311+
if (KeyCode == VK_MULTI_SCREENSHOT) { keybd_event(VK_F12, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0); keybd_event(VK_F12, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); } // Steam
312+
313+
} else if (KeyCode == VK_STEAM_SCREENSHOT) {
314+
keybd_event(VK_F12, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
295315

296316
} else if (KeyCode == VK_FULLSCREEN || KeyCode == VK_FULLSCREEN_PLUS) {
297317
keybd_event(VK_RETURN, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
@@ -313,11 +333,12 @@ struct _AppStatus {
313333
int GamepadEmulationMode;
314334
bool XboxGamepadAttached = true;
315335
bool AimMode = false;
336+
int LeftStickMode = 0;
316337
bool ChangeModesWithoutPress = false;
317338
bool ShowBatteryStatus = false;
339+
int ScreenshotMode = 0;
318340
bool ExternalPedalsConnected = false;
319-
};
320-
_AppStatus AppStatus;
341+
}; _AppStatus AppStatus;
321342

322343
// https://github.com/JibbSmart/JoyShockLibrary/blob/master/JoyShockLibrary/JoyShock.cpp
323344
uint32_t crc_table[256] = {

0 commit comments

Comments
 (0)