-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmouse2joystick_citra.ahk
1614 lines (1518 loc) · 48.8 KB
/
mouse2joystick_citra.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
; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;
; Further modified for Citra by epigramx for the use in the guide: https://community.citra-emu.org/t/how-to-use-a-mouse-as-a-virtual-joystick-in-citra-in-order-to-control-a-camera-view-or-for-custom-mouse-input/1885
version := "2017-06-01_2"
;
; Modified for CEMU by: CemuUser8 (https://www.reddit.com/r/cemu/comments/5zn0xa/autohotkey_script_to_use_mouse_for_camera/)
; Last Modified Date: 2017-05-31
;
; Original Author: Helgef
; Date: 2016-08-17
;
; Description:
; Mouse to keyboard or 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
;
#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.
#MaxHotkeysPerInterval 210
#HotkeyInterval 1000
#InstallMouseHook
#SingleInstance Force
; Settings
CoordMode,Mouse,Screen
SetMouseDelay,-1
SetBatchLines,-1
; On exit
OnExit("exitFunc")
toggle:=1 ; On/off parameter for the hotkey. Toggle 0 means controller is on. The placement of this variable is disturbing.
; Icon
Menu,Tray,Tip, mouse2joystick_citra
Menu,Tray,NoStandard
try
Menu,Tray,Icon,ddores.dll,26
;Menu,Settings,openSettings
Menu,Tray,Add,Settings,openSettings
Menu,Tray,Add,
Menu,Tray,Add,About,aboutMenu
Menu,Tray,Add
Menu,Tray,Add,Reload,reloadMenu
Menu,Tray,Add,Exit,exitFunc
; 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]
gameExe=Citra-qt.exe
mouse2joystick=1
autoActivateGame=1
firstRun=1
vJoyDevice=1
[General>Setup]
r=40
k=0.02
fallBackPause=-1
nnp=.65
[General>Hotkeys]
controllerSwitchKey=F1
exitKey=#q
[Mouse2Joystick>Axes]
angularDeadZone=0
invertedX=0
invertedY=1
[Mouse2Joystick>Keys]
joystickButtonKeyList=Space,LButton,q,e,Up,Down,Left,Right,RButton,MButton,Enter,RShift,1,3,g,w,s,a,d
autoHoldStickKey=
fixRadiusKey=
[KeyboardMovement>Keys]
upKey=w
downKey=s
leftKey=a
rightKey=d
walkToggleKey=Numpad0
lockZLToggleKey=Numpad1
[Extra Settings]
hideCursor=1
BotWmouseWheel=0
lockZL=0
nnVA=1
)
FileAppend,%defaultSettings%,settings.ini
If ErrorLevel
{
Msgbox,% 6+16,Error writing to file., There was a problem creating settings.ini
, make sure you have permision to write to file at %A_ScriptDir%. If the problem persists`, try to run as administator 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
}
}
; 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.
angularDeadZone*=pi/180 ; Convert to radians
angularDeadZone:=angularDeadZone>pi/4 ? pi/4:angularDeadZone ; Ensure correct range
; 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 := []
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).
Hotkey,%controllerSwitchKey%,controllerSwitch, on
Hotkey,%exitKey%,exitFunc, on
freq:=25 ; Controllers update frequency, in ms.
actionTaken:=0 ; For handling quick fall back to center. Needs to start at zero.
mouse2joystick := True
if mouse2joystick
{
Gosub, initCvJoyInterface
Gosub, mouse2joystickHotkeys
}
pmX:=invertedX ? -1:1 ; Sign for inverting axis
pmY:=invertedY ? -1:1
snapToFullTilt:=0.005 ; This needs to be improved.
fr:=0 ; Fixed radius.
;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
stickIsAutoHeld:=0 ; Tracks the status of autohold stick. 0 means it is not being auto held.
;fallBackPause:=125 ; Short mouse movement block after fall back. Set to zero to disable fallback
segmentEndAngles:=Object() ; Each segment is defined by its angle, segment 1,...,12 -> end angle pi/6,pi/3,...,2*pi [rad]. (Unfortuantley its clockwise, with 0/2pi being at three o'clock)
Loop,12
segmentEndAngles[A_Index]:=pi/6*A_Index
; 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.
IniWrite,0,settings.ini,General,firstRun
}
Return
; End autoexec.
reloadMenu:
Reload
return
aboutMenu:
Msgbox,32,About, mouse2joystick_citra`n`n`Version: %version%`n`nModified for Citra by epigramx,`nbased on CemuUser8's modified mouse2joystick,`noriginally by Helgef
return
return
initCvJoyInterface:
; Copied from joytest.ahk, from CvJoyInterface by evilC
; Create an object from vJoy Interface Class.
vJoyInterface := new CvJoyInterface()
; Was vJoy installed and the DLL Loaded?
if (!vJoyInterface.vJoyEnabled()){
; Show log of what happened
Msgbox,% 4+16,vJoy Error,% "vJoy needs to be installed. Press no to exit application.`nLog:`n" . vJoyInterface.LoadLibraryLog ; Error handling changed.
IfMsgBox Yes
{
;IniWrite, 0,settings.ini,General,mouse2joystick
reload
}
ExitApp
}
ValidDevices := ""
Loop 15
{
IF (vJoyInterface.Devices[A_Index].IsAvailable())
ValidDevices .= A_Index . "|"
}
global vstick := vJoyInterface.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
}
else
{
gameX:=0
gameY:=0
gameW:=A_ScreenWidth
gameH:=A_ScreenHeight
}
DllCall("User32.dll\ReleaseCapture") ; Release mouse capture from game.
; 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
Gui, Controller:+LastFound
WinSet,Transparent,1,ahk_id %stick% ; Make transparent.
DllCall("User32.dll\SetCapture", "Uint", stick) ; Let the controller capture the mouse.
if hideCursor
DllCall("User32.dll\ShowCursor", "Int", 0)
if mouse2joystick
SetTimer,mouseTojoystick,%freq%
}
else ; Shutting down controller
{
if mouse2joystick
{
SetTimer,mouseTojoystick,Off
setStick(0,0) ; Stick in equllibrium.
setStick(0,0, True)
}
if hideCursor
DllCall("User32.dll\ShowCursor", "Int", 1) ; No need to show cursor if not hidden.
DllCall("User32.dll\ReleaseCapture") ; This might be unnecessary
stickIsAutoHeld:=0 ; Ensure stick is not being held
WinHide, ahk_id %stick%
}
toggle:=!toggle
return
autoHoldStick:
;
; Sub-routine for enabling user to lock joystick position and use mouse normally.
;
if !stickIsAutoHeld
{
; Here the stick is not being auto held and user wants to auto hold it.
if hideCursor
DllCall("User32.dll\ShowCursor", "Int", 1) ; Show cursor
WinHide, ahk_id %stick%
DllCall("User32.dll\ReleaseCapture")
MouseGetPos,ahX,ahY ; Save mouse position
MouseMove,OX,OY ; Move mouse
if mouse2joystick
SetTimer, mouseTojoystick, Off ; Shut down timer
}
else
{
; Here the stick is being auto held and user wants to get back control.
if hideCursor
DllCall("User32.dll\ShowCursor", "Int", 0) ; Hide cursor again
WinShow, ahk_id %stick%
DllCall("User32.dll\SetCapture", "Uint", stick) ; Let the controller capture the mouse.
MouseMove,ahX,ahY ; Move back mouse.
if mouse2joystick
SetTimer, mouseTojoystick, on ; Turn timer back on.
}
stickIsAutoHeld:=!stickIsAutoHeld ; Toggle auto hold status
return
; Hotkeys mouse2joystick
#if (!toggle && mouse2joystick)
#if
mouse2joystickHotkeys:
Hotkey, if, (!toggle && mouse2joystick)
SetStick(0,0, True)
HotKey,%walkToggleKey%,toggleHalf, On
IF (lockZLToggleKey AND lockZL)
HotKey,%lockZLToggleKey%,toggleAimLock, On
IF (BotWmouseWheel) {
Hotkey,WheelUp, overwriteWheelUp, on
Hotkey,WheelDown, overwriteWheelDown, 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, `,
{
keyName:=A_LoopField
if !keyName
continue
KeyList[keyName] := A_Index
Hotkey,%keyName%, pressJoyButton, on
Hotkey,%keyName% Up, releaseJoyButton, on
}
if autoHoldStickKey
HotKey, %autoHoldStickKey%, autoHoldStick, On
if fixRadiusKey
HotKey, %fixRadiusKey%, fixRadius, On
Hotkey, if
return
fixRadius:
if fr ; Toggle fixed/free.
{
fr:=0
return
}
MouseGetPos,X,Y
X-=OX ; Move to controller coord system.
Y-=OY
fr:=sqrt(X**2+Y**2) ; Fix radius to current deflection.
return
; Labels for pressing and releasing joystick buttons.
pressJoyButton:
keyName:=A_ThisHotkey
joyButtonNumber := KeyList[keyName] ; joyButtonNumber:=A_Index
if (joyButtonNumber = 7 AND lockZL) {
IF (ZLToggle)
vstick.SetBtn(0,joyButtonNumber)
Else
vstick.SetBtn(1,joyButtonNumber)
}
Else if joyButtonNumber
vstick.SetBtn(1,joyButtonNumber)
return
releaseJoyButton:
keyName:=RegExReplace(A_ThisHotkey," Up$")
joyButtonNumber := KeyList[keyName] ; joyButtonNumber:=A_Index
if (joyButtonNumber = 7 AND lockZL) {
IF (ZLToggle)
vstick.SetBtn(1,joyButtonNumber)
Else
vstick.SetBtn(0,joyButtonNumber)
}
Else if joyButtonNumber
vstick.SetBtn(0,joyButtonNumber)
return
toggleAimLock:
vstick.SetBtn((ZLToggle := !ZLToggle),7)
Return
toggleHalf:
moveStickHalf := !moveStickHalf
IF (GetKeyState(downKey, "P"))
SetStick("N/A",(moveStickHalf ? 0.5 : 1), True)
IF (GetKeyState(rightKey, "P"))
SetStick((moveStickHalf ? 0.5 : 1),"N/A", True)
IF (GetKeyState(leftKey, "P"))
SetStick((moveStickHalf ? -0.5 : -1),"N/A", True)
IF (GetKeyState(upKey, "P"))
SetStick("N/A",(moveStickHalf ? -0.5 : -1), True)
Return
overwriteUp:
Critical
IF (moveStickHalf)
SetStick("N/A",-0.5, True)
Else
SetStick("N/A",-1, True)
Return
overwriteUpup:
Critical
IF (GetKeyState(downKey, "P")) {
IF (moveStickHalf)
SetStick("N/A",0.5, True)
Else
SetStick("N/A",1, True)
}
Else
SetStick("N/A",0, True)
Return
overwriteLeft:
Critical
IF (moveStickHalf)
SetStick(-0.5,"N/A", True)
Else
SetStick(-1,"N/A", True)
Return
overwriteLeftup:
Critical
IF (GetKeyState(rightKey, "P")) {
IF (moveStickHalf)
SetStick(0.5,"N/A", True)
Else
SetStick(1,"N/A", True)
}
Else
SetStick(0,"N/A", True)
Return
overwriteRight:
Critical
IF (moveStickHalf)
SetStick(0.5,"N/A", True)
Else
SetStick(1,"N/A", True)
Return
overwriteRightup:
Critical
IF (GetKeyState(leftKey, "P")) {
IF (moveStickHalf)
SetStick(-0.5,"N/A", True)
Else
SetStick(-1,"N/A", True)
}
Else
SetStick(0,"N/A", True)
Return
overwriteDown:
Critical
IF (moveStickHalf)
SetStick("N/A",0.5, True)
Else
SetStick("N/A",1, True)
Return
overwriteDownup:
Critical
IF (GetKeyState(upKey, "P")) {
IF (moveStickHalf)
SetStick("N/A",-0.5, True)
Else
SetStick("N/A",-1, True)
}
Else
SetStick("N/A",0, True)
Return
overwriteWheelUp:
SetStick(0,0)
IF (!alreadyDown){
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){
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:
vstick.SetBtn(0,16)
alreadyDown := False
SetTimer, ReleaseDPad, Off
Return
; Labels
mouseTojoystick:
mouse2joystick(r,dr,OX,OY)
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.
; fr is the fixed radius
global actionTaken, fallBackPause, k, nnp, fr, AlreadyDown
MouseGetPos,X,Y
X-=OX ; Move to controller coord system.
Y-=OY
RR:=sqrt(X**2+Y**2)
if fr ; If fixed radius.
{
X:=round(X*fr/RR)
Y:=round(Y*fr/RR)
RR:=sqrt(X**2+Y**2)
MouseMove,X+OX,Y+OY
}
else 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.
{
; Call action function.
action(phi,((RR-k*r)/(r-k*r))**nnp) ; nnp is a non-linearity parameter.
actionTaken:=1 ; This will enable fall back to center when leaving outer ring.
}
else
{
setStick(0,0) ; Stick in equllibrium.
if (fallBackPause!=-1 && actionTaken=1)
{
MouseMove,OX,OY ; User has moved back to inner circle/deadzone, fall back to center.
mouseBlock() ; Short mouse movmement block after fallback.
actionTaken:=0 ; This will enable leaving the inner circle/deadzone again.
}
}
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 angularDeadZone,pmX,pmY,pi,snapToFullTilt
; Adjust tilt
tilt:=tilt>1 ? 1:tilt
if (snapToFullTilt!=-1)
tilt:=1-tilt<=snapToFullTilt ? 1:tilt
; If in angular deadzone, only output to one axis is done, for easy "full tilt" in one direction without any small drift to other direction.
; In angular deadzone, the output is "output"
if (phi<3*pi/2+angularDeadZone && phi>3*pi/2-angularDeadZone) ; In angular deadzone for Y-axis forward tilt.
{
setStick(0,pmY*tilt)
return
}
if (phi<pi+angularDeadZone && phi>pi-angularDeadZone) ; In angular deadzone for X-axis left tilt.
{
setStick(-pmX*tilt,0)
return
}
if (phi<pi/2+angularDeadZone && phi>pi/2-angularDeadZone) ; In angular deadzone for Y-axis down tilt.
{
setStick(0,-pmY*tilt)
return
}
if ((phi>2*pi-angularDeadZone && phi<2*pi) || (phi<angularDeadZone && phi>=0) ) ; In angular deadzone for Y-axis right tilt.
{
setStick(pmX*tilt,0)
return
}
; Not inside angular deadzone. Here leq and geq should be used. There are eight cases.
; Two cases with forward+right
; Tilt is forward and slightly right.
lb:=3*pi/2+angularDeadZone ; 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-angularDeadZone ; 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:=angularDeadZone ; 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-angularDeadZone ; 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+angularDeadZone ; 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-angularDeadZone ; 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+angularDeadZone ; 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-angularDeadZone ; 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:
x:=(x+1)*16384 ; This maps x,y ∈ (-1,1) -> (0,32768)
y:=(y+1)*16384
; Use set by index.
; x = 1, y = 2.
; Alter x
IF ( a ) { ;IF (GetKeyState("RButton") OR a ) {
axisX := 4
axisY := 5
}
Else {
axisX := 1
axisY := 2
}
IF x is number
vstick.SetAxisByIndex(x,axisX)
; Alter y
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
}
mouseBlock()
{
global fallBackPause
BlockInput, MouseMove
Sleep, %fallBackPause%
BlockInput, MouseMoveOff
}
exitFunc()
{
global
if mouse2Joystick
{
setStick(0,0)
SetStick(0,0, True)
vstick.Relinquish()
}
BlockInput, MouseMoveOff
DllCall("User32.dll\ShowCursor", "Int", 1)
ExitApp
}
; Misc labels and such
tipOff:
Tooltip
return
;
; End Script.
; Start settings.
; This is auto generated.
;
openSettings:
if !toggle ; This is probably best.
return
Gui, Main: Destroy ; Ops
hideShow=0
win_name := "mouse2joystick_citra Settings v." . version
submitOnlyOne:=0
GoSub,readTreeString
Gui, Main: -Resize
GUI, Main: add, text, x10 , Options:
Gui, Main: Add, TreeView, vMainTreeVar r16 w150 gTreeClick
Gui, Main: Add, button, x10 w100 gmainOk ,Ok
GUI, Main: Add, StatusBar
SB_SetParts(150,50)
GoSub,guiCode
GUI, Main:+HwndMAIN_HWND
Gui, Main: Show,, %win_name%
Main_WinTitle=ahk_id %MAIN_HWND%
GuiControl, -Redraw, Main
Gui, Main: default
TV_LoadTree(tree)
GuiControl, +Redraw, Main
return
TreeClick:
lastSection:=section
if A_GuiEvent = S
selection:=A_EventInfo
section:=selectionPath(selection)
SB_SetText("You are in: " . section,1)
TV_GetText(nodeName,selection)
if (IsLabel(lastSection))
{
hideShow=0
Gosub,%lastSection%
}
section:=RegExReplace(section,"[ ]+","_")
if (IsLabel(section))
{
hideShow=1
Gosub,%section%
hideShow=0
}
return
mainOk:
Gui, Main: Submit
Gosub, SubmitAll
; Get old hotkeys.
; Disable old hotkeys
Hotkey,%controllerSwitchKey%,controllerSwitch, off
Hotkey,%exitKey%,exitFunc, off
; Joystick buttons
Hotkey, if, (!toggle && mouse2joystick)
HotKey,%walkToggleKey%,toggleHalf, Off
IF (lockZLToggleKey AND lockZL)
HotKey,%lockZLToggleKey%,toggleAimLock, Off
IF (BotWmouseWheel) {
Hotkey,WheelUp, overwriteWheelUp, off
Hotkey,WheelDown, overwriteWheelDown, off
}
Hotkey,%upKey%, overwriteUp, off
Hotkey,%upKey% Up, overwriteUpup, off
Hotkey,%leftKey%, overwriteLeft, off
Hotkey,%leftKey% Up, overwriteLeftup, off
Hotkey,%downKey%, overwriteDown, off
Hotkey,%downKey% Up, overwriteDownup, off
Hotkey,%rightKey%, overwriteRight, off
Hotkey,%rightKey% Up, overwriteRightup, off
Loop, Parse, joystickButtonKeyList, `,
{
keyName:=A_LoopField
if !keyName
continue
KeyList[keyName] := ""
Hotkey,%keyName%, pressJoyButton, off
Hotkey,%keyName% Up, releaseJoyButton, off
}
if autoHoldStickKey
HotKey, %autoHoldStickKey%, autoHoldStick, off
if fixRadiusKey
HotKey, %fixRadiusKey%, fixRadius, off
Hotkey, if
; Read settings.
IniRead,allSections,settings.ini
Loop,Parse,allSections,`n
{
IniRead,pairs,settings.ini,%A_LoopField%
Loop,Parse,pairs,`n
{
StringSplit,keyValue,A_LoopField,=
%keyValue1%:=keyValue2
}
}
if mouse2joystick
{
Gosub, initCvJoyInterface
Gosub, mouse2joystickHotkeys
}
pmX:=invertedX ? -1:1 ; Sign for inverting axis
pmY:=invertedY ? -1:1
angularDeadZone*=pi/180 ; Convert to radians
angularDeadZone:=angularDeadZone>pi/4 ? pi/4:angularDeadZone ; Ensure correct range
; Enable new hotkeys
Hotkey,%controllerSwitchKey%,controllerSwitch, on
Hotkey,%exitKey%,exitFunc, on
return
guiCode:
Iniread,editText,settings.ini,General,gameExe
editText:=RegExReplace(editText,"DELIM_\|_ITER","`n")
Gui, Main: add, Edit,Hidden vedit1092695107 X185 Y115 r1 w150,%editText%
editText=
Gui, Main: add, GroupBox,Hidden vtext23478877 X170 Y25 W520 H64,Output mode
Gui, Main: add, GroupBox,Hidden vtext1153671792 X170 Y95 W520 H53,Input desitnation
Gui, Main: add, GroupBox,Hidden vtext1396826083 X170 Y155 W520 H45,Activate Executable
Gui, Main: add, GroupBox,Hidden vvJoyGroupBox X170 Y215 W520 H53,vJoy Device
Iniread,master_var,settings.ini,General,mouse2joystick
checkMe:= (master_var="1") ? 1:0
Gui, Main: Add, Radio, Hidden Section Group Checked%checkMe% vradio1244113855_1 X185 Y45, Mouse2Joystick (requires vJoy)
checkMe:= (master_var="0") ? 1:0
;Gui, Main: Add, Radio, Hidden Checked%checkMe% vradio1244113855_2, Mouse2Keyboard
Iniread,master_var,settings.ini,General,autoActivateGame
checkMe:= (master_var="1") ? 1:0
Gui, Main: Add, Radio, Hidden Section Group Checked%checkMe% vradio1371042200_1 X185 Y175, Yes
checkMe:= (master_var="0") ? 1:0
Gui, Main: Add, Radio, Hidden ys Checked%checkMe% vradio1371042200_2, No
Text=
(
The name of the executable that will receive the output.
)
Gui, Main: add, Text,Hidden vtext1439415306 X350 Y118,%Text%
Text=
Text=
(
Automatically activate executable (if it is running) when controller is switched on.
)
Gui, Main: add, Text,Hidden vtext1649409801 X285 Y175,%Text%
Text=
Gui, Main: add, DropDownList, Hidden vvJoyDropDown Section X185 Y235, %ValidDevices%
useList := RegExReplace(ValidDevices, "(^|\|)" . vJoyDevice . "(\||$)", "$1" . vJoyDevice . "|$2")
GuiControl, Main:,vJoyDropDown, % "|" . useList
Iniread,editText,settings.ini,General>Setup,r
editText:=RegExReplace(editText,"DELIM_\|_ITER","`n")
Gui, Main: add, Edit,Hidden Number vedit968841594 X185 Y45 r1 w75,%editText%
editText=
Iniread,editText,settings.ini,General>Setup,k
editText:=RegExReplace(editText,"DELIM_\|_ITER","`n")
Gui, Main: add, Edit,Hidden vedit1484171716 X185 Y165 r1 w75,%editText%
editText=
Iniread,editText,settings.ini,General>Setup,fallBackPause
editText:=RegExReplace(editText,"DELIM_\|_ITER","`n")
Gui, Main: add, Edit,Hidden vedit1441011004 X185 Y225 r1 w75,%editText%
editText=
Iniread,editText,settings.ini,General>Setup,nnp
editText:=RegExReplace(editText,"DELIM_\|_ITER","`n")
Gui, Main: add, Edit,Hidden vedit1136845697 X185 Y105 r1 w75,%editText%
editText=
Gui, Main: add, GroupBox,Hidden vtext1820027441 X170 Y25 W520 H53,Sensitivity
Gui, Main: add, GroupBox,Hidden vtext1761503059 X170 Y85 W520 H53,Non linear sensitivity
Gui, Main: add, GroupBox,Hidden vtext868645638 X170 Y145 W520 H53,Deadzone
Gui, Main: add, GroupBox,Hidden vtext303295627 X171 Y205 W520 H53,Fallback pause
Text=
(
1 is linear, <1 lowers sensitivity away from center, >1 hightens sensitivity away center.
)
Gui, Main: add, Text,Hidden vtext1950133817 X270 Y109,%Text%
Text=
Text=
(
Range, (0,1). The center area where no output is sent.
)
Gui, Main: add, Text,Hidden vtext1365655690 X270 Y169,%Text%
Text=
Text=
(
ms. Snaps back to center when entering inner ring, and pauses. Set to -1 to disable.
)
Gui, Main: add, Text,Hidden vtext1314749378 X270 Y227,%Text%
Text=
Text=
(
Range, (0,Screen Height/2). Lower values corresponds to higher sensitivity.
)
Gui, Main: add, Text,Hidden vtext68851252 X270 Y48,%Text%
Text=
Gui, Main: add, GroupBox,Hidden vtext495210823 X170 Y25 W520 H72,Quit application
Gui, Main: add, GroupBox,Hidden vtext199783574 X170 Y105 W520 H72,Toggle the controller on/off
;Gui, Main: add, GroupBox,Hidden vtext1265532956 X170 Y185 W520 H72,Enable/disable movement of visual aid
Iniread,master_var,settings.ini,General>Hotkeys,controllerSwitchKey
hotkey26759803_oldkey:=master_var
Gui, Main: add, Hotkey, Hidden 0 vhotkey26759803 X185 Y125 W150,% RegExReplace(master_var,"#")