diff --git a/OBS_Scene_Switcher.ahk b/OBS_Scene_Switcher.ahk index 21c0a71..011dc75 100644 --- a/OBS_Scene_Switcher.ahk +++ b/OBS_Scene_Switcher.ahk @@ -1,6 +1,10 @@ #Warn +#NoEnv #SingleInstance, Force +keybdkey := "F13" ; This determines what gets sent from keyboard/mouse inputs +controllerkey := "F14" ; This determines what gets sent from controller inputs + ; From the AHK documentation, used to auto-detect the joystick number JoystickNumber := 0 if (JoystickNumber <= 0){ @@ -12,7 +16,7 @@ if (JoystickNumber <= 0){ } if (JoystickNumber <= 0 ){ - MsgBox, Could not detect any joysticks! + MsgBox, 16, OBS Scene Switcher, % "ERROR: Could not detect any joysticks! Program will exit." ExitApp } } @@ -35,15 +39,17 @@ if (axis_3 != 0){ ; Only create the variables if the axis exists for the control previousJoyR := "" } +cInput := Func("OnInput").Bind(controllerkey) ; Create bound function object and bind the controller key to it, so it can be used with the Hotkey command + Loop, % joy_buttons { ; Turns all the controller buttons into hotkeys - Hotkey, % JoystickNumber "Joy" A_Index, OnGamepadUsed, On + Hotkey, % JoystickNumber "Joy" A_Index, % cInput, On } ; An input hook used for intercepting all keyboard keys (excluding modifiers) ih := InputHook("V L0 I") ih.KeyOpt("{All}", "N") ih.KeyOpt("{LCtrl}{RCtrl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}", "-N") -ih.OnKeyDown := Func("OnKeyPressed") +ih.OnKeyDown := Func("OnInput").Bind(keybdkey) ih.Start() return @@ -53,7 +59,7 @@ return ~RButton:: ~LButton:: Sleep, 150 -OnKeyPressed() +OnInput(keybdkey) return ;**********************************/Timers/******************************************************* @@ -62,17 +68,17 @@ check_mouse: ; The subroutine that checks mouse movement MouseGetPos, cx, cy if (cx != sx or cy != sy){ if (cx > (sx+50) or cx < (sx-50) or cy > (sy+50) or cy < (sy-50)){ - OnKeyPressed() + OnInput(keybdkey) MouseGetPos, sx, sy } } return -check_axes: +check_axes: ; The subroutine that checks controller axes joyX := GetKeyState(JoystickNumber . "JoyX") joyY := GetKeyState(JoystickNumber . "JoyY") if (!IsValueSimilar(previousJoyX, joyX) || !IsValueSimilar(previousJoyY, joyY)){ - OnGamepadUsed() + cInput.Call() previousJoyX := joyX previousJoyY := joyY } @@ -80,8 +86,8 @@ check_axes: if (axis_3 != 0){ ; Only check the state if the axis exists joyZ := GetKeyState(JoystickNumber . "JoyZ") joyR := GetKeyState(JoystickNumber . "JoyR") - if (!IsValueSimilar(previousJoyZ, joyZ) || !IsValueSimilar(previousJoyR, joyR)){ - OnGamepadUsed() + if (!IsValueSimilar(previousJoyR, joyR) || !IsValueSimilar(previousJoyZ, joyZ)){ + cInput.Call() previousJoyZ := joyZ previousJoyR := joyR } @@ -90,29 +96,22 @@ check_axes: if (dpad != 0){ ; Only check POV state if it exists joy_p := GetKeyState(JoyStickNumber . "JoyPOV") if(joy_p != -1 && joy_p != "") - OnGamepadUsed() + cInput.Call() } return ;**********************************/Functions/******************************************************* -OnKeyPressed(){ ; A function that sends a keystroke to OBS when a keyboard key is pressed/the mouse has moved - Critical - SetKeyDelay, 10 - SetTitleMatchMode, 2 - ControlSend, ahk_parent, {Blind}{F13}, OBS ; 'F13' can be changed to whatever key you want -} - -OnGamepadUsed(){ ; A function that sends a keystroke to OBS when a controller button is pressed/an analog stick has moved +OnInput(key){ Critical SetKeyDelay, 10 SetTitleMatchMode, 2 - ControlSend, ahk_parent, {Blind}{F14}, OBS ; 'F14' can be changed to whatever key you want + ControlSend, ahk_parent, {Blind}{%key%}, OBS } IsValueSimilar(var1, var2){ ; A function that compares the previous and current states of the controller axes return ((var1 - 7) <= var2) && ((var1 + 7) >= var2) } - +;**************************************************************************************************** ; Kill-switch Shift+F4 +F4::ExitApp