-
Notifications
You must be signed in to change notification settings - Fork 56
/
mouse2joystick_Custom_CEMU.ahk
1854 lines (1694 loc) · 53.4 KB
/
mouse2joystick_Custom_CEMU.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
; Modified for CEMU by: CemuUser8 (https://www.reddit.com/r/cemu/comments/5zn0xa/autohotkey_script_to_use_mouse_for_camera/)
; Last Modified Date: 2020-05-19
;
; Original Author: Helgef
; Date: 2016-08-17
;
; Description:
; Mouse to virtual joystick. For virtual joystick you need to install vJoy. See url below.
;
; Notes:
; -#q exit at any time.
;
; Urls:
; https://autohotkey.com/boards/viewtopic.php?f=19&t=21489 - First released here / help / instruction / bug reports.
; http://vjoystick.sourceforge.net/site/ - vJoy device drivers, needed for mouse to virtual joystick.
; https://autohotkey.com/boards/viewtopic.php?f=19&t=20703&sid=2619d57dcbb0796e16ea172f238f08a0 - Original request by crisangelfan.
; https://autohotkey.com/boards/viewtopic.php?t=5705 - CvJoyInterface.ahk
;
; Acknowledgements:
; crisangelfan and evilC on autohotkey.com forum provided useful input.
; Credit to author(s) of vJoy @ http://vjoystick.sourceforge.net/site/
; evilC did the CvJoyInterface.ahk
;
version := "v0.4.1.4"
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;#Include CvJI/CvJoyInterface.ahk ; Credit to evilC.
#Include CvJI/CvGenInterface.ahk ; A Modifed Interface that I (CemuUser8) added the vXBox device and functions to.
#Include CvJI/MouseDelta.ahk ; Alternate way to see mouse movement
#Include CvJI/SelfDeletingTimer.ahk
; Settings
#MaxHotkeysPerInterval 210
#HotkeyInterval 1000
#InstallMouseHook
#SingleInstance Force
CoordMode,Mouse,Screen
SetMouseDelay,-1
SetBatchLines,-1
; On exit
OnExit("exitFunc")
IF (A_PtrSize < 8) {
MsgBox,16,Now Requires 64bit, Starting with Version 0.4.0.0 this program requires 64bit. If you are getting this error you must be running the script directly and have 32bit AutoHotkey installed.`n`nPlease either use the released executable, or change your AutoHotkey installation to the 64bit Unicode version
ExitApp
}
;OrigMouseSpeed := ""
;DllCall("SystemParametersInfo", UInt, 0x70, UInt, 0, UIntP, OrigMouseSpeed, UInt, 0) ; Get Original Mouse Speed.
toggle:=1 ; On/off parameter for the hotkey. Toggle 0 means controller is on. The placement of this variable is disturbing.
; If no settings file, create, When changing this, remember to make corresponding changes after the setSettingsToDefault label (error handling) ; Currently at bottom of script
IfNotExist, settings.ini
{
defaultSettings=
(
[General]
usevXBox=0
vJoyDevice=1
vXBoxDevice=1
gameExe=Cemu.exe
autoActivateGame=1
[General>Setup]
r=30
k=0.02
freq=75
nnp=.80
[General>Hotkeys]
controllerSwitchKey=F1
exitKey=#q
[Mouse2Joystick>Axes]
invertedX=0
invertedY=0
[Mouse2Joystick>Keys]
joystickButtonKeyList=e,LShift,Space,LButton,1,3,LCtrl,RButton,Enter,m,q,c,i,k,j,l,b
[Keyboard Movement>Keys]
upKey=w
leftKey=a
downKey=s
rightKey=d
walkToggleKey=Numpad0
increaseWalkKey=NumpadAdd
decreaseWalkKey=NumPadSub
walkSpeed=0.5
gyroToggleKey=
[Extra Settings]
BotWmouseWheel=0
lockZL=0
lockZLToggleKey=Numpad1
hideCursor=1
BotWmotionAim=0
useAltMouseMethod=0
alt_xSen=400
alt_ySen=280
)
FileAppend,%defaultSettings%,settings.ini
IF (ErrorLevel) {
Msgbox,% 6+16,Error writing to file., There was a problem creating settings.ini
, make sure you have permission to write to file at %A_ScriptDir%. If the problem persists`, try to run as administrator or change the script directory. Press retry to try again`, continue to set all settings to default or cancel to exit application.
IfMsgBox Retry
reload
Else IfMsgBox Continue
Goto, setSettingsToDefault ; Currently at bottom of script
Else
ExitApp
}
firstRun := True ; Moved out of ini File.
}
; Read settings.
IniRead,allSections,settings.ini
IF (!allSections || allSections="ERROR") { ; Do not think this is ever set to ERROR.
MsgBox, % 2+16, Error reading file, There was an error reading the settings.ini file`, press retry to try again`, continue to set all settings to default or cancel to exit application.
IfMsgBox retry
reload
Else IfMsgBox Ignore
Goto, setSettingsToDefault ; Currently at bottom of script
Else
ExitApp
}
Loop,Parse,allSections,`n
{
IniRead,pairs,settings.ini,%A_LoopField%
Loop,Parse,pairs,`n
{
StringSplit,keyValue,A_LoopField,=
%keyValue1%:=keyValue2
}
}
readSettingsSkippedDueToError: ; This comes from setSettingsToDefault If there was an error.
pi:=atan(1)*4 ; Approx pi.
; Constants and such. Some values are commented out because they have been stored in the settings.ini file instead, but are kept because they have comments.
moveStickHalf := False
KeyList := []
KeyListByNum := []
md := new MouseDelta("MouseEvent")
ih := InputHook()
ih.KeyOpt("{All}", "ES")
dr:=0 ; Bounce back when hit outer circle edge, in pixels. (This might not work any more, it is off) Can be seen as a force feedback parameter, can be extended to depend on the over extension beyond the outer ring.
; Hotkey(s).
IF (controllerSwitchKey)
Hotkey,%controllerSwitchKey%,controllerSwitch, on
IF (exitKey)
Hotkey,%exitKey%,exitFunc, on
mouse2joystick := True
IF (mouse2joystick) {
Gosub, initCvJoyInterface
Gosub, mouse2joystickHotkeys
}
; Icon
Menu,Tray,Tip, mouse2joystick Customized for CEMU
Menu,Tray,NoStandard
IF (!A_IsCompiled) { ; If it is compiled it should just use the EXE Icon
IF (A_OSVersion < "10.0.15063") ; It appears that the Icon has changed number on the newest versions of Windows.
useIcon := 26
Else IF (A_OSVersion >= "10.0.16299")
useIcon := 28
Else
useIcon := 27
Try
Menu,Tray,Icon,ddores.dll, %useIcon%
}
;Menu,Settings,openSettings
Menu,Tray,Add,Settings,openSettings
Menu,Tray,Add,
IF (vGenInterface.IsVBusExist())
Menu,Tray,Add,Uninstall ScpVBus, uninstallBus
Else
Menu,Tray,Add,Install ScpVBus, installBus
Menu,Tray,Add,
Menu,Tray,Add,Reset to CEMU, selectGameMenu
Menu,Tray,Add
Menu,Tray,Add,About,aboutMenu
Menu,Tray,Add,Help,helpMenu
Menu,Tray,Add
Menu,Tray,Add,Reload,reloadMenu
Menu,Tray,Add,Exit,exitFunc
Menu,Tray,Default, Settings
IF freq is not Integer
freq := 75
pmX:=invertedX ? -1:1 ; Sign for inverting axis
pmY:=invertedY ? -1:1
snapToFullTilt:=0.005 ; This needs to be improved.
;nnp:=4 ; Non-linearity parameter for joystick output, 1 = linear, >1 higher sensitivity closer to full tilt, <1 higher sensitivity closer to deadzone. Recommended range, [0.1,6].
; New parameters
; Mouse blocker
; Transparent window that covers game screen to prevent game from capture the mouse.
Gui, Controller: New
Gui, Controller: +ToolWindow -Caption +AlwaysOnTop +HWNDstick
Gui, Controller: Color, FFFFFF
; Spam user with useless info, first time script runs.
IF (firstRun)
MsgBox,64,Welcome,Settings are accessed via Tray icon -> Settings.
Return
; End autoexec.
selectGameMenu:
TrayTip, % "Game reset to cemu.exe", % "If you want something different manually edit the settings, or 'settings.ini' file directly",,0x10
gameExe := "cemu.exe"
IniWrite, %gameExe%, settings.ini, General, gameExe
Return
reloadMenu:
Reload
Return
aboutMenu:
Msgbox,32,About, Modified for CEMU by:`nCemuUser8`n`nVersion:`n%version%
Return
helpMenu:
Msgbox,% 4 + 32 , Open help in browser?, Visit Reddit post on /r/cemu for help?`n`nIt is helpful to know the version (%version%)`nand If possible a pastebin of your 'settings.ini' file will help me troubleshoot.`n`nWill Open link in default browser.
IfMsgBox Yes
Run, https://www.reddit.com/r/cemu/comments/5zn0xa/autohotkey_script_to_use_mouse_for_camera/
Return
initCvJoyInterface:
Global vXBox := usevXBox
; Copied from joytest.ahk, from CvJoyInterface by evilC
; Create an object from vJoy Interface Class.
vGenInterface := new CvGenInterface()
; Was vJoy installed and the DLL Loaded?
IF (!vGenInterface.vJoyEnabled()){
; Show log of what happened
Msgbox,% 4+16,vJoy Error,% "vJoy needs to be installed. Press no to exit application.`nLog:`n" . vGenInterface.LoadLibraryLog ; Error handling changed.
IfMsgBox Yes
{
;IniWrite, 0,settings.ini,General,mouse2joystick
reload
}
ExitApp
}
IF (vXBox AND !vGenInterface.IsVBusExist()) {
Msgbox,% 4 + 32 , Virtual xBox Bus not found, Press Yes If you would like to install ScpVBus, otherwise script will revert back to vJoy instead of vXBox.`n`nScript will reload after installing.
IfMsgBox Yes
InstallUninstallScpVBus(True)
Else {
vXBox := False
IniWrite,0, settings.ini, General, usevXBox ; Turn off the setting for the next run as well.
}
}
ValidDevices := ""
Loop 15 {
IF (vGenInterface.Devices[A_Index].IsAvailable())
ValidDevices .= A_Index . "|"
}
IF (vXBox) {
IF (vXboxDevice != vstick.DeviceID OR !vstick.GetLedNumber()) {
IF (isObject(vstick)) {
vstick.Unplug()
vstick.Relinquish()
}
;vGenInterface.UnPlugAll() ; Not sure how this interacts when a real controller is also plugged in. But I seem to notice that there is an issue if not ran.
Global vstick := vGenInterface.xDevices[vXBoxDevice]
vstick.Acquire()
TrayTip,, % "Controller #" vstick.GetLedNumber()
}
}
Else {
IF (isObject(vstick)) {
vstick.Unplug()
vstick.Relinquish()
}
Global vstick := vGenInterface.Devices[vJoyDevice]
}
Return
; Hotkey labels
; This switches on/off the controller.
controllerSwitch:
IF (toggle) { ; Starting controller
IF (autoActivateGame) {
WinActivate,ahk_exe %gameExe%
WinWaitActive, ahk_exe %gameExe%,,2
IF (ErrorLevel) {
MsgBox,16,Error, %gameExe% not activated.
Return
}
WinGetPos,gameX,gameY,gameW,gameH,ahk_exe %gameExe% ; Get game screen position and dimensions
WinGet, gameID, ID, ahk_exe %gameExe%
}
Else {
gameX:=0
gameY:=0
gameW:=A_ScreenWidth
gameH:=A_ScreenHeight
}
; Controller origin is center of game screen or screen If autoActivateGame:=0.
OX:=gameX+gameW/2
OY:=gameY+gameH/2
IF (!OX OR !OY) {
OX := 500
OY := 500
}
; Move mouse to controller origin
MouseMove,OX,OY
; The mouse blocker
Gui, Controller: Show,NA x%gameX% y%gameY% w%gameW% h%gameH%,Controller
WinSet,Transparent,1,ahk_id %stick%
IF (hideCursor)
show_Mouse(False)
;DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, 10, UInt, 0)
IF (useAltMouseMethod) {
md.Start()
LockMouseToWindow("ahk_id " . stick)
}
Else
SetTimer,mouseTojoystick,%freq%
}
Else { ; Shutting down controller
setStick(0,0) ; Stick in equilibrium.
setStick(0,0, True)
IF (useAltMouseMethod) {
LockMouseToWindow(False)
md.Stop()
}
Else
SetTimer,mouseTojoystick,Off
IF (hideCursor)
show_Mouse() ; No need to show cursor if not hidden.
;DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, OrigMouseSpeed, UInt, 0) ; Restore the original speed.
Gui, Controller:Hide
}
toggle:=!toggle
Return
; Hotkeys mouse2joystick
#IF (!toggle && mouse2joystick)
#IF
mouse2joystickHotkeys:
Hotkey, IF, (!toggle && mouse2joystick)
SetStick(0,0, True)
IF (walkToggleKey)
HotKey,%walkToggleKey%,toggleHalf, On
IF (decreaseWalkKey)
HotKey,%decreaseWalkKey%,decreaseWalk, On
IF (increaseWalkKey)
HotKey,%increaseWalkKey%,increaseWalk, On
IF (lockZLToggleKey AND lockZL)
HotKey,%lockZLToggleKey%,toggleAimLock, On
IF (BotWmouseWheel) {
Hotkey,WheelUp, overwriteWheelUp, on
Hotkey,WheelDown, overwriteWheelDown, on
}
IF (gyroToggleKey) {
HotKey,%gyroToggleKey%, GyroControl, on
HotKey,%gyroToggleKey% Up, GyroControlOff, on
}
Hotkey,%upKey%, overwriteUp, on
Hotkey,%upKey% Up, overwriteUpup, on
Hotkey,%leftKey%, overwriteLeft, on
Hotkey,%leftKey% Up, overwriteLeftup, on
Hotkey,%downKey%, overwriteDown, on
Hotkey,%downKey% Up, overwriteDownup, on
Hotkey,%rightKey%, overwriteRight, on
Hotkey,%rightKey% Up, overwriteRightup, on
KeyList := []
Loop, Parse, joystickButtonKeyList, `,
{
useButton := A_Index
Loop, Parse, A_LoopField, |
{
keyName:=A_LoopField
IF (!keyName)
Continue
KeyList[keyName] := useButton
Hotkey,%keyName%, pressJoyButton, on
Hotkey,%keyName% Up, releaseJoyButton, on
}
}
Hotkey, IF
Return
; Labels for pressing and releasing joystick buttons.
pressJoyButton:
keyName:=A_ThisHotkey
joyButtonNumber := KeyList[keyName] ; joyButtonNumber:=A_Index
If InStr(keyName, "wheel")
new SelfDeletingTimer(100, "ReleaseWheel", joyButtonNumber)
IF (!vXBox){
IF (joyButtonNumber = 7 AND lockZL) {
IF (ZLToggle)
vstick.SetBtn(0,joyButtonNumber)
Else
vstick.SetBtn(1,joyButtonNumber)
}
Else IF (joyButtonNumber = 8 AND BotWmotionAim) {
GoSub, GyroControl
vstick.SetBtn(1,joyButtonNumber)
}
Else IF (joyButtonNumber)
vstick.SetBtn(1,joyButtonNumber)
}
Else {
Switch joyButtonNumber
{
Case 7:
IF (lockZL AND ZLToggle)
vstick.SetAxisByIndex(0,6)
Else
vstick.SetAxisByIndex(100,6)
return
Case 8:
vstick.SetAxisByIndex(100,3)
return
Case 9:
vstick.SetBtn(1,joyButtonNumber-1)
return
Case 10:
vstick.SetBtn(1,joyButtonNumber-3)
return
Case 11,12:
vstick.SetBtn(1,joyButtonNumber-2)
return
Case 13:
vstick.SetPOV(0)
return
Case 14:
vstick.SetPOV(180)
return
Case 15:
vstick.SetPOV(270)
return
Case 16:
vstick.SetPOV(90)
return
Default:
vstick.SetBtn(1,joyButtonNumber)
return
}
}
Return
ReleaseWheel(keyNum) { ; This is duplicated of the label below, it had to be added so I could release mouse wheel keys as they don't fire Up keystrokes.
Global
IF (!vXBox){
IF (keyNum = 7 AND lockZL) {
IF (ZLToggle)
vstick.SetBtn(1,keyNum)
Else
vstick.SetBtn(0,keyNum)
}
Else IF (keyNum = 8 AND BotWmotionAim) {
vstick.SetBtn(0,keyNum)
GoSub, GyroControlOff
}
Else IF (keyNum)
vstick.SetBtn(0,keyNum)
}
Else {
Switch keyNum
{
Case 7:
IF (lockZL AND ZLToggle)
vstick.SetAxisByIndex(100,6)
Else
vstick.SetAxisByIndex(0,6)
Case 8:
vstick.SetAxisByIndex(0,3)
Case 9:
vstick.SetBtn(0,keyNum-1)
Case 10:
vstick.SetBtn(0,keyNum-3)
Case 11,12:
vstick.SetBtn(0,keyNum-2)
Case 13,14,15,16:
vstick.SetPOV(-1)
Default:
vstick.SetBtn(0,keyNum)
}
}
Return
}
releaseJoyButton:
keyName:=RegExReplace(A_ThisHotkey," Up$")
joyButtonNumber := KeyList[keyName] ; joyButtonNumber:=A_Index
IF (!vXBox){
IF (joyButtonNumber = 7 AND lockZL) {
IF (ZLToggle)
vstick.SetBtn(1,joyButtonNumber)
Else
vstick.SetBtn(0,joyButtonNumber)
}
Else IF (joyButtonNumber = 8 AND BotWmotionAim) {
vstick.SetBtn(0,joyButtonNumber)
GoSub, GyroControlOff
}
Else IF (joyButtonNumber)
vstick.SetBtn(0,joyButtonNumber)
}
Else {
Switch joyButtonNumber
{
Case 7:
IF (lockZL AND ZLToggle)
vstick.SetAxisByIndex(100,6)
Else
vstick.SetAxisByIndex(0,6)
Case 8:
vstick.SetAxisByIndex(0,3)
Case 9:
vstick.SetBtn(0,joyButtonNumber-1)
Case 10:
vstick.SetBtn(0,joyButtonNumber-3)
Case 11,12:
vstick.SetBtn(0,joyButtonNumber-2)
Case 13,14,15,16:
vstick.SetPOV(-1)
Default:
vstick.SetBtn(0,joyButtonNumber)
}
}
Return
GyroControl:
;DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, 4, UInt, 0) ; Slow mouse movement down a little bit
IF (BotWmouseWheel) {
Hotkey, If, (!toggle && mouse2joystick)
Hotkey,WheelUp, overwriteWheelUp, off
Hotkey,WheelDown, overwriteWheelDown, off
}
SetStick(0,0)
Gui, Controller:Hide
IF (!useAltMouseMethod) {
LockMouseToWindow("ahk_id " . gameID)
SetTimer, mouseTojoystick, Off
}
Click, Right, Down
Return
GyroControlOff:
Click, Right, Up
IF (BotWmouseWheel) {
Hotkey, If, (!toggle && mouse2joystick)
Hotkey,WheelUp, overwriteWheelUp, on
Hotkey,WheelDown, overwriteWheelDown, on
}
;DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, 10, UInt, 0) ; Restore the original speed.
Gui, Controller:Show, NA
IF (!useAltMouseMethod){
LockMouseToWindow()
SetTimer, mouseTojoystick, On
}
Return
toggleAimLock:
IF (vXbox)
vstick.SetAxisByIndex((ZLToggle := !ZLToggle) ? 100 : 0,6)
Else
vstick.SetBtn((ZLToggle := !ZLToggle),7)
Return
toggleHalf:
moveStickHalf := !moveStickHalf
KeepStickHowItWas()
Return
decreaseWalk:
walkSpeed -= 0.05
IF (walkSpeed < 0)
walkSpeed := 0
KeepStickHowItWas()
IniWrite, % walkSpeed:= Round(walkSpeed, 2), settings.ini, Keyboard Movement>Keys, walkSpeed
GUI, Main:Default
GUIControl,,opwalkSpeedTxt, % Round(walkSpeed * 100) "%"
Return
increaseWalk:
walkSpeed += 0.05
IF (walkSpeed > 1)
walkSpeed := 1
KeepStickHowItWas()
IniWrite, % walkSpeed := Round(walkSpeed, 2), settings.ini, Keyboard Movement>Keys, walkSpeed
GUI, Main:Default
GUIControl,,opwalkSpeedTxt, % Round(walkSpeed * 100) "%"
Return
KeepStickHowItWas() {
Global moveStickHalf, walkSpeed, upKey, leftKey, downKey, rightKey
IF (GetKeyState(downKey, "P"))
SetStick("N/A",(moveStickHalf ? -1 * walkSpeed : -1), True)
IF (GetKeyState(rightKey, "P"))
SetStick((moveStickHalf ? 1 * walkSpeed : 1),"N/A", True)
IF (GetKeyState(leftKey, "P"))
SetStick((moveStickHalf ? -1 * walkSpeed : -1),"N/A", True)
IF (GetKeyState(upKey, "P"))
SetStick("N/A",(moveStickHalf ? 1 * walkSpeed : 1), True)
}
overwriteUp:
Critical, On
IF (moveStickHalf)
SetStick("N/A",1 * walkSpeed, True)
Else
SetStick("N/A",1, True)
Critical, Off
Return
overwriteUpup:
Critical, On
IF (GetKeyState(downKey, "P")) {
IF (moveStickHalf)
SetStick("N/A",-1 * walkSpeed, True)
Else
SetStick("N/A",-1, True)
}
Else
SetStick("N/A",0, True)
Critical, Off
Return
overwriteLeft:
Critical, On
IF (moveStickHalf)
SetStick(-1 * walkSpeed,"N/A", True)
Else
SetStick(-1,"N/A", True)
Critical, Off
Return
overwriteLeftup:
Critical, On
IF (GetKeyState(rightKey, "P")) {
IF (moveStickHalf)
SetStick(1 * walkSpeed,"N/A", True)
Else
SetStick(1,"N/A", True)
}
Else
SetStick(0,"N/A", True)
Critical, Off
Return
overwriteRight:
Critical, On
IF (moveStickHalf)
SetStick(1 * walkSpeed,"N/A", True)
Else
SetStick(1,"N/A", True)
Critical, Off
Return
overwriteRightup:
Critical, On
IF (GetKeyState(leftKey, "P")) {
IF (moveStickHalf)
SetStick(-1 * walkSpeed,"N/A", True)
Else
SetStick(-1,"N/A", True)
}
Else
SetStick(0,"N/A", True)
Critical, Off
Return
overwriteDown:
Critical, On
IF (moveStickHalf)
SetStick("N/A",-1 * walkSpeed, True)
Else
SetStick("N/A",-1, True)
Critical, Off
Return
overwriteDownup:
Critical, On
IF (GetKeyState(upKey, "P")) {
IF (moveStickHalf)
SetStick("N/A",1 * walkSpeed, True)
Else
SetStick("N/A",1, True)
}
Else
SetStick("N/A",0, True)
Critical, Off
Return
overwriteWheelUp:
SetStick(0,0)
IF (!alreadyDown){
IF (vXbox)
vstick.SetPOV(90)
Else
vstick.SetBtn(1,16)
alreadyDown := True
DllCall("Sleep", Uint, 250)
}
SetStick(-1,0)
DllCall("Sleep", Uint, 30)
SetStick(0,0)
SetTimer, ReleaseDPad, -650 ; vstick.SetBtn(0,16)
Return
overwriteWheelDown:
SetStick(0,0)
IF (!alreadyDown){
IF (vXbox)
vstick.SetPOV(90)
Else
vstick.SetBtn(1,16)
alreadyDown := True
DllCall("Sleep", Uint, 250)
}
SetStick(1,0)
DllCall("Sleep", Uint, 30)
SetStick(0,0)
SetTimer, ReleaseDPad, -650 ; vstick.SetBtn(0,16)
Return
ReleaseDPad:
IF (vXbox)
vstick.SetPOV(-1)
Else
vstick.SetBtn(0,16)
alreadyDown := False
SetTimer, ReleaseDPad, Off
Return
; Labels
mouseTojoystick:
Critical, On
mouse2joystick(r,dr,OX,OY)
Critical, Off
Return
; Functions
mouse2joystick(r,dr,OX,OY) {
; r is the radius of the outer circle.
; dr is a bounce back parameter.
; OX is the x coord of circle center.
; OY is the y coord of circle center.
Global k, nnp, AlreadyDown
MouseGetPos,X,Y
X-=OX ; Move to controller coord system.
Y-=OY
RR:=sqrt(X**2+Y**2)
IF (RR>r) { ; Check If outside controller circle.
X:=round(X*(r-dr)/RR)
Y:=round(Y*(r-dr)/RR)
RR:=sqrt(X**2+Y**2)
MouseMove,X+OX,Y+OY ; Calculate point on controller circle, move back to screen/window coords, and move mouse.
}
; Calculate angle
phi:=getAngle(X,Y)
IF (RR>k*r AND !AlreadyDown) ; Check If outside inner circle/deadzone.
action(phi,((RR-k*r)/(r-k*r))**nnp) ; nnp is a non-linearity parameter.
Else
setStick(0,0) ; Stick in equllibrium.
MouseMove,OX,OY
}
action(phi,tilt) {
; This is for mouse2joystick.
; phi ∈ [0,2*pi] defines in which direction the stick is tilted.
; tilt ∈ (0,1] defines the amount of tilt. 0 is no tilt, 1 is full tilt.
; When this is called it is already established that the deadzone is left, or the inner radius.
; pmX/pmY is used for inverting axis.
; snapToFullTilt is used to ensure full tilt is possible, this needs to be improved, should be dependent on the sensitivity.
Global pmX,pmY,pi,snapToFullTilt
; Adjust tilt
tilt:=tilt>1 ? 1:tilt
IF (snapToFullTilt!=-1)
tilt:=1-tilt<=snapToFullTilt ? 1:tilt
; Two cases with forward+right
; Tilt is forward and slightly right.
lb:=3*pi/2 ; lb is lower bound
ub:=7*pi/4 ; ub is upper bound
IF (phi>=lb && phi<=ub)
{
x:=pmX*tilt*scale(phi,ub,lb)
y:=pmY*tilt
setStick(x,y)
Return
}
; Tilt is slightly forward and right.
lb:=7*pi/4 ; lb is lower bound
ub:=2*pi ; ub is upper bound
IF (phi>=lb && phi<=ub)
{
x:=pmX*tilt
y:=pmY*tilt*scale(phi,lb,ub)
setStick(x,y)
Return
}
; Two cases with right+downward
; Tilt is right and slightly downward.
lb:=0 ; lb is lower bound
ub:=pi/4 ; ub is upper bound
IF (phi>=lb && phi<=ub)
{
x:=pmX*tilt
y:=-pmY*tilt*scale(phi,ub,lb)
setStick(x,y)
Return
}
; Tilt is downward and slightly right.
lb:=pi/4 ; lb is lower bound
ub:=pi/2 ; ub is upper bound
IF (phi>=lb && phi<=ub)
{
x:=pmX*tilt*scale(phi,lb,ub)
y:=-pmY*tilt
setStick(x,y)
Return
}
; Two cases with downward+left
; Tilt is downward and slightly left.
lb:=pi/2 ; lb is lower bound
ub:=3*pi/4 ; ub is upper bound
IF (phi>=lb && phi<=ub)
{
x:=-pmX*tilt*scale(phi,ub,lb)
y:=-pmY*tilt
setStick(x,y)
Return
}
; Tilt is left and slightly downward.
lb:=3*pi/4 ; lb is lower bound
ub:=pi ; ub is upper bound
IF (phi>=lb && phi<=ub)
{
x:=-pmX*tilt
y:=-pmY*tilt*scale(phi,lb,ub)
setStick(x,y)
Return
}
; Two cases with forward+left
; Tilt is left and slightly forward.
lb:=pi ; lb is lower bound
ub:=5*pi/4 ; ub is upper bound
IF (phi>=lb && phi<=ub)
{
x:=-pmX*tilt
y:=pmY*tilt*scale(phi,ub,lb)
setStick(x,y)
Return
}
; Tilt is forward and slightly left.
lb:=5*pi/4 ; lb is lower bound
ub:=3*pi/2 ; ub is upper bound
IF (phi>=lb && phi<=ub)
{
x:=-pmX*tilt*scale(phi,lb,ub)
y:=pmY*tilt
setStick(x,y)
Return
}
; This should not happen:
setStick(0,0)
MsgBox,16,Error, Error at phi=%phi%. Please report.
Return
}
scale(phi,lb,ub) {
; let phi->f(phi) then, f(ub)=0 and f(lb)=1
Return (phi-ub)/(lb-ub)
}
setStick(x,y, a := False) {
; Set joystick x-axis to 100*x % and y-axis to 100*y %
; Input is x,y ∈ (-1,1) where 1 would mean full tilt in one direction, and -1 in the other, while zero would mean no tilt at all. Using this interval makes it easy to invert the axis
; (mainly this was choosen beacause the author didn't know the correct interval to use in CvJoyInterface)
; the input is not really compatible with the CvJoyInterface. Hence this transformation:
IF (vXBox) {
x:=(x+1)*50 ; This maps x,y (-1,1) -> (0,100)
y:=(y+1)*50
}
Else {
x:=(x+1)*16384 ; This maps x,y (-1,1) -> (0,32768)
y:=(y+1)*16384
}
; Use set by index.
; x = 1, y = 2.
IF ( (!a AND vXbox) OR (a AND !vXBox) ) { ; IF (GetKeyState("RButton") OR a ) {
axisX := 4
axisY := 5
}
Else {
axisX := 1
axisY := 2
}
IF x is number
vstick.SetAxisByIndex(x,axisX)
IF y is number
vstick.SetAxisByIndex(y,axisY)
}
; Shared functions
getAngle(x,y) {
Global pi
IF (x=0)
Return 3*pi/2-(y>0)*pi
phi:=atan(y/x)
IF (x<0 && y>0)
Return phi+pi
IF (x<0 && y<=0)
Return phi+pi
IF (x>0 && y<0)
Return phi+2*pi
Return phi
}
exitFunc() {
Global
IF (mouse2Joystick) {
setStick(0,0)
SetStick(0,0, True)
IF (vXBox)
vstick.UnPlug()
vstick.Relinquish()
}
md.Delete()
md := ""
show_Mouse() ; DllCall("User32.dll\ShowCursor", "Int", 1)
;DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, OrigMouseSpeed, UInt, 0) ; Restore the original speed.
ExitApp
}
;
; End Script.
; Start settings.
;
openSettings:
If !toggle ; This is probably best.
Return
tree := "
(
General|Setup,Hotkeys
Mouse2Joystick|Axes,Keys
Keyboard Movement|Keys
Extra Settings
)"
GUI, Main:New, -MinimizeBox, % "Mouse2Joystick Custom for CEMU Settings - " . version
GUI, Add, Text,, Options:
GUI, Add, TreeView, xm w150 r16 gTreeClick Section
GUI, Add, Button,xs w73 gMainOk, Ok
GUI, Add, Button,x+4 w73 gMainSave Default, Save
GUI, Add, Tab2, +Buttons -Theme -Wrap vTabControl ys w320 h0 Section, General|General>Setup|General>Hotkeys|Mouse2Joystick|Mouse2Joystick>Axes|Mouse2Joystick>Keys|Keyboard Movement|Keyboard Movement>Keys|Extra Settings
GUIControlGet, S, Pos, TabControl ; Store the coords of this section for future use.
;------------------------------------------------------------------------------------------------------------------------------------------
GUI, Tab, General
GUI, Add, GroupBox, x%SX% y%SY% w320 h120 Section, Output Mode
GUI, Add, Radio, % "xp+10 yp+20 Group vopusevXBox Checked" . !usevXBox, Use vJoy Device (Direct Input)
GUI, Add, Radio, % "xp yp+20 Checked" . usevXBox, Use vXBox Device (XInput)
GUI, Add, GroupBox, xs+10 yp+20 w90 h50 Section,vJoy Device
GUI, Add, DropDownList, xp+10 yp+20 vopvJoyDevice w70, % StrReplace(ValidDevices, vJoyDevice, vJoyDevice . "|")
GUI, Add, GroupBox, ys w90 h50,vXBox Device
GUI, Add, DropDownList, xp+10 yp+20 vopvXBoxDevice w70, % StrReplace("1|2|3|4|", vXBoxDevice, vXBoxDevice . "|")
GUI, Add, GroupBox, x%SX% yp+45 w320 h50,Executable Name
GUI, Add, Edit, xp+10 yp+20 vopgameExe w90, %gameExe%
GUI, Add, Text, x+m yp+3, The executable name for your CEMU
GUI, Add, GroupBox, x%SX% yp+35 w320 h40,Auto Activate Executable
GUI, Add, Radio, % "xp+10 yp+20 Group vopautoActivateGame Checked" !autoActivateGame, No
GUI, Add, Radio, % "x+m Checked" autoActivateGame, Yes
GUI, Add, Text, x+m, Switch to CEMU when toggling controller?
;------------------------------------------------------------------------------------------------------------------------------------------
GUI, Tab, General>Setup
GUI, Add, GroupBox, x%SX% y%SY% w320 h50 Section, Sensitivity