@@ -134,7 +134,7 @@ SHORT DeadZoneXboxAxis(SHORT StickAxis, float Percent)
134134
135135int main (int argc, char **argv)
136136{
137- SetConsoleTitle (" DS4Emulator 1.8" );
137+ SetConsoleTitle (" DS4Emulator 1.8.1 " );
138138
139139 CIniReader IniFile (" Config.ini" ); // Config
140140
@@ -195,8 +195,9 @@ int main(int argc, char **argv)
195195 int EmulationMode = KBMode;
196196
197197 // Config parameters
198- int KEY_ID_EXIT = KeyNameToKeyCode (IniFile.ReadString (" Main" , " ExitBtn" , " ~" )); // "~" by default for RU, US and not for UK
199- int KEY_ID_STOP_CENTERING = KeyNameToKeyCode (IniFile.ReadString (" KeyboardMouse" , " StopCenteringKey" , " C" ));
198+ std::string KEY_ID_STOP_CENTERING_NAME = IniFile.ReadString (" KeyboardMouse" , " StopCenteringKey" , " C" );
199+ int KEY_ID_STOP_CENTERING = KeyNameToKeyCode (KEY_ID_STOP_CENTERING_NAME);
200+ bool CenteingEnable = true ;
200201
201202 bool InvertX = IniFile.ReadBoolean (" Main" , " InvertX" , false );
202203 bool InvertY = IniFile.ReadBoolean (" Main" , " InvertY" , false );
@@ -207,6 +208,11 @@ int main(int argc, char **argv)
207208 bool TouchPadPressedWhenSwiping = IniFile.ReadBoolean (" Xbox" , " TouchPadPressedWhenSwiping" , true );
208209 bool EnableXboxButton = IniFile.ReadBoolean (" Xbox" , " EnableXboxButton" , true );
209210
211+ std::string KEY_ID_XBOX_SHAKING_1_NAME = IniFile.ReadString (" Xbox" , " MotionShakingKey1" , " BACK" );
212+ int KEY_ID_XBOX_SHAKING_1 = XboxKeyNameToXboxKeyCode (KEY_ID_XBOX_SHAKING_1_NAME);
213+ std::string KEY_ID_XBOX_SHAKING_2_NAME = IniFile.ReadString (" Xbox" , " MotionShakingKey2" , " RIGHT-SHOULDER" );
214+ int KEY_ID_XBOX_SHAKING_2 = XboxKeyNameToXboxKeyCode (KEY_ID_XBOX_SHAKING_2_NAME);
215+
210216 float DeadZoneLeftStickX = IniFile.ReadFloat (" Xbox" , " DeadZoneLeftStickX" , 0 );
211217 float DeadZoneLeftStickY = IniFile.ReadFloat (" Xbox" , " DeadZoneLeftStickY" , 0 );
212218 float DeadZoneRightStickX = IniFile.ReadFloat (" Xbox" , " DeadZoneRightStickX" , 0 );
@@ -227,23 +233,23 @@ int main(int argc, char **argv)
227233 mouseSensetiveY = IniFile.ReadFloat (" KeyboardMouse" , " SensY" , 15 );
228234 int DeadZoneDS4 = IniFile.ReadInteger (" KeyboardMouse" , " DeadZone" , 0 ); // 25, makes mouse movement smoother when moving slowly (12->25)
229235
230- int KEY_ID_LEFT_STICK_UP = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " LS_UP " , " W" ));
231- int KEY_ID_LEFT_STICK_LEFT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " LS_LEFT " , " A" ));
232- int KEY_ID_LEFT_STICK_RIGHT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " LS_RIGHT " , " D" ));
233- int KEY_ID_LEFT_STICK_DOWN = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " LS_DOWN " , " S" ));
236+ int KEY_ID_LEFT_STICK_UP = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " LEFT-STICK-UP " , " W" ));
237+ int KEY_ID_LEFT_STICK_LEFT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " LEFT-STICK-LEFT " , " A" ));
238+ int KEY_ID_LEFT_STICK_RIGHT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " LEFT-STICK-RIGHT " , " D" ));
239+ int KEY_ID_LEFT_STICK_DOWN = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " LEFT-STICK-DOWN " , " S" ));
234240 int KEY_ID_LEFT_TRIGGER = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " L2" , " MOUSE-RIGHT-BTN" ));
235241 int KEY_ID_RIGHT_TRIGGER = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " R2" , " MOUSE-LEFT-BTN" ));
236- int KEY_ID_LEFT_SHOULDER = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " L1" , " CTRL " ));
237- int KEY_ID_RIGHT_SHOULDER = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " R1" , " ALT " ));
238- int KEY_ID_DPAD_UP = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " DPAD_UP " , " 1" ));
239- int KEY_ID_DPAD_LEFT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " DPAD_LEFT " , " 2" ));
240- int KEY_ID_DPAD_RIGHT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " DPAD_RIGHT " , " 3" ));
241- int KEY_ID_DPAD_DOWN = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " DPAD_DOWN " , " 4" ));
242+ int KEY_ID_LEFT_SHOULDER = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " L1" , " ALT " ));
243+ int KEY_ID_RIGHT_SHOULDER = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " R1" , " CTRL " ));
244+ int KEY_ID_DPAD_UP = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " DPAD-UP " , " 1" ));
245+ int KEY_ID_DPAD_LEFT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " DPAD-LEFT " , " 2" ));
246+ int KEY_ID_DPAD_RIGHT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " DPAD-RIGHT " , " 3" ));
247+ int KEY_ID_DPAD_DOWN = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " DPAD-DOWN " , " 4" ));
242248 int KEY_ID_LEFT_THUMB = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " L3" , " SHIFT" ));
243249 int KEY_ID_RIGHT_THUMB = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " R3" , " MOUSE-MIDDLE-BTN" ));
244- int KEY_ID_TRIANGLE = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TRIANGLE" , " Q " ));
245- int KEY_ID_SQUARE = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " SQUARE" , " E " ));
246- int KEY_ID_CIRCLE = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " CIRCLE" , " R " ));
250+ int KEY_ID_TRIANGLE = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TRIANGLE" , " E " ));
251+ int KEY_ID_SQUARE = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " SQUARE" , " R " ));
252+ int KEY_ID_CIRCLE = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " CIRCLE" , " Q " ));
247253 int KEY_ID_CROSS = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " CROSS" , " SPACE" ));
248254 int KEY_ID_SHARE = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " SHARE" , " F12" ));
249255 int KEY_ID_TOUCHPAD = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD" , " ENTER" ));
@@ -252,16 +258,16 @@ int main(int argc, char **argv)
252258
253259 int KEY_ID_SHAKING = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " SHAKING" , " T" ));
254260
255- int KEY_ID_TOUCHPAD_SWIPE_UP = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD_SWIPE_UP " , " 7" ));
256- int KEY_ID_TOUCHPAD_SWIPE_DOWN = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD_SWIPE_DOWN " , " 8" ));
257- int KEY_ID_TOUCHPAD_SWIPE_LEFT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD_SWIPE_LEFT " , " 9" ));
258- int KEY_ID_TOUCHPAD_SWIPE_RIGHT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD_SWIPE_RIGHT " , " 0" ));
261+ int KEY_ID_TOUCHPAD_SWIPE_UP = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD-SWIPE-UP " , " 7" ));
262+ int KEY_ID_TOUCHPAD_SWIPE_DOWN = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD-SWIPE-DOWN " , " 8" ));
263+ int KEY_ID_TOUCHPAD_SWIPE_LEFT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD-SWIPE-LEFT " , " 9" ));
264+ int KEY_ID_TOUCHPAD_SWIPE_RIGHT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD-SWIPE-RIGHT " , " 0" ));
259265
260- int KEY_ID_TOUCHPAD_UP = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD_UP " , " U" ));
261- int KEY_ID_TOUCHPAD_DOWN = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD_DOWN " , " N" ));
262- int KEY_ID_TOUCHPAD_LEFT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD_LEFT " , " H" ));
263- int KEY_ID_TOUCHPAD_RIGHT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD_RIGHT " , " K" ));
264- int KEY_ID_TOUCHPAD_CENTER = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD_CENTER " , " J" ));
266+ int KEY_ID_TOUCHPAD_UP = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD-UP " , " U" ));
267+ int KEY_ID_TOUCHPAD_DOWN = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD-DOWN " , " N" ));
268+ int KEY_ID_TOUCHPAD_LEFT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD-LEFT " , " H" ));
269+ int KEY_ID_TOUCHPAD_RIGHT = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD-RIGHT " , " K" ));
270+ int KEY_ID_TOUCHPAD_CENTER = KeyNameToKeyCode (IniFile.ReadString (" Keys" , " TOUCHPAD-CENTER " , " J" ));
265271
266272 const auto client = vigem_alloc ();
267273 auto ret = vigem_connect (client);
@@ -300,22 +306,24 @@ int main(int argc, char **argv)
300306 }
301307
302308 // Write current mode
303- if (EmulationMode == XboxMode)
309+ if (EmulationMode == XboxMode) {
304310 printf (" \n Emulation with Xbox controller.\n " );
305- else {
311+ printf_s (" Touchpad press: \" BACK\" .\n Touchpad movement: \" BACK\" + \" RIGHT-STICK\" .\n Motion shaking: \" %s\" + \" %s\" .\n " , KEY_ID_XBOX_SHAKING_1_NAME.c_str (), KEY_ID_XBOX_SHAKING_2_NAME.c_str ());
312+
313+ } else {
306314 printf (" \r\n Emulation with keyboard and mouse.\n " );
307315 if (ActivateInAnyWindow == false )
308316 printf (" Activate in any window is disabled, so the emulated gamepad work only in \" PS Plus\" and \" PS4 Remote Play\" .\n " );
309- printf (" Hold down \" C \" to for cursor movement .\n " );
317+ printf_s (" Enable or disable cursor movement on the \" %s \" button (right stick emulation) .\n " , KEY_ID_STOP_CENTERING_NAME. c_str () );
310318 }
311319 if (EmulationMode == KBMode) {
312320 printf (" Press \" ALT\" + \" F10\" to switch \" PS Plus\" to full-screen mode or return to normal.\n " );
313321 if (CursorHidden)
314- printf (" The cursor is hidden. To display the cursor, press \" ALT\" + \" Escape\" or \" exit key \" .\n " );
322+ printf (" The cursor is hidden. To display the cursor, press \" ALT\" + \" Escape\" .\n " );
315323 else
316324 printf (" The cursor is not hidden. To hide the cursor, press \" ALT\" + \" F2\" .\n " );
317325 }
318- printf (" Press \" ALT\" + \" Escape\" or \" exit key \" to exit.\n " );
326+ printf (" Press \" ALT\" + \" Escape\" to exit.\n " );
319327
320328 DS4_TOUCH BuffPreviousTouch[2 ] = { 0 , 0 };
321329 BuffPreviousTouch[0 ].bIsUpTrackingNum1 = 0x80 ;
@@ -324,7 +332,7 @@ int main(int argc, char **argv)
324332 bool AllowIncTouchIndex;
325333 bool DeadZoneMode = false ;
326334
327- while (!(( GetAsyncKeyState (KEY_ID_EXIT) & 0x8000 ) || (( GetAsyncKeyState (VK_LMENU) & 0x8000 ) && ( GetAsyncKeyState (VK_ESCAPE) & 0x8000 )) )) // "~" by default
335+ while ( !( ( GetAsyncKeyState (VK_LMENU) & 0x8000 && GetAsyncKeyState (VK_ESCAPE) & 0x8000 ) ) )
328336 {
329337 DS4_REPORT_INIT_EX (&report);
330338
@@ -356,7 +364,7 @@ int main(int argc, char **argv)
356364 if (DeadZoneMode == false ) {
357365 system (" cls" );
358366 printf (" \n Emulation with Xbox controller.\n " );
359- printf (" Press \" ALT\" + \" Escape\" or \" exit key \" to exit.\n " );
367+ printf (" Press \" ALT\" + \" Escape\" to exit.\n " );
360368 }
361369 SkipPollCount = SkipPollTimeOut;
362370 }
@@ -412,10 +420,11 @@ int main(int argc, char **argv)
412420 if (EnableXboxButton && myPState.Gamepad .wButtons & XINPUT_GAMEPAD_GUIDE) report.bSpecial |= DS4_SPECIAL_BUTTON_PS;
413421
414422 // Motion shaking
415- if (myPState.Gamepad .wButtons & XINPUT_GAMEPAD_BACK && myPState.Gamepad .wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER ) {
416- myPState.Gamepad .wButtons &= ~XINPUT_GAMEPAD_BACK ; myPState.Gamepad .wButtons &= ~XINPUT_GAMEPAD_RIGHT_SHOULDER ;
423+ if (myPState.Gamepad .wButtons & KEY_ID_XBOX_SHAKING_1 && myPState.Gamepad .wButtons & KEY_ID_XBOX_SHAKING_2 ) {
424+ myPState.Gamepad .wButtons &= ~KEY_ID_XBOX_SHAKING_1 ; myPState.Gamepad .wButtons &= ~KEY_ID_XBOX_SHAKING_2 ;
417425 MotionShaking = true ;
418- } else MotionShaking = false ;
426+ } else
427+ MotionShaking = false ;
419428
420429 // Swap share and touchpad
421430 if (SwapShareTouchPad == false ) {
@@ -490,7 +499,7 @@ int main(int argc, char **argv)
490499
491500 // Touchpad swipes
492501 if (report.bSpecial & DS4_SPECIAL_BUTTON_TOUCHPAD) {
493- if (!TouchPadPressedWhenSwiping && (report.bThumbRX != 127 || report.bThumbRY != 129 ) ) {
502+ if (!TouchPadPressedWhenSwiping && (report.bThumbRX != 127 || report.bThumbRY != 129 )) {
494503 report.bSpecial &= ~DS4_SPECIAL_BUTTON_TOUCHPAD;
495504 if (myPState.Gamepad .wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) { report.wButtons &= ~DS4_BUTTON_THUMB_RIGHT; report.bSpecial |= DS4_SPECIAL_BUTTON_TOUCHPAD; }
496505 }
@@ -534,12 +543,13 @@ int main(int argc, char **argv)
534543
535544 if (CursorHidden == false && (GetAsyncKeyState (VK_LMENU) & 0x8000 ) && (GetAsyncKeyState (VK_F2) & 0x8000 ) && SkipPollCount == 0 ) {
536545 SetSystemCursor (CursorEmpty, OCR_NORMAL); CursorHidden = true ;
537- printf (" The cursor is hidden. To display the cursor, press \" ALT\" + \" Escape\" or \" exit key \" .\n " );
546+ printf (" The cursor is hidden. To display the cursor, press \" ALT\" + \" Escape\" .\n " );
538547 SkipPollCount = SkipPollTimeOut;
539548 }
540549
541550 if (ActivateInAnyWindow || PSNowFound || PSRemotePlayFound) {
542- if ((GetAsyncKeyState (KEY_ID_STOP_CENTERING) & 0x8000 ) == 0 ) GetMouseState ();
551+ if (GetAsyncKeyState (KEY_ID_STOP_CENTERING) & 0x8000 && SkipPollCount == 0 ) { CenteingEnable = !CenteingEnable; SkipPollCount = SkipPollTimeOut;}
552+ if (CenteingEnable) GetMouseState ();
543553
544554 if (InvertX)
545555 DeltaMouseX = DeltaMouseX * -1 ;
0 commit comments