Tool [Tool] Bind Mouse to Stardew Valley

Discussion in 'Mods' started by tarumes, May 31, 2017.

  1. tarumes

    tarumes Void-Bound Voyager

    Hey

    If you Play Stardew Valley with Controller in Window Mode
    you can move your Cursor outside the Window
    to prevent this here is my little AutoIT tool
    to bind mouse to Stardew Valley

    HotKey TogglePause Shift-Alt-p
    HotKey Exit Shift-Alt-x

    Source is aviable in ZIP

    Have Fun

    Config File is generated on first Launch

    margin_top=35
    margin_left=15
    margin_right=15
    margin_bottom=15
    Sleep=20 <-- never set this to 0 or below



    31.05.2017 Version 0.0.0.5
    Add Comments to SourceCode
    Download



    Code:
    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_UseX64=n
    #AutoIt3Wrapper_Res_Fileversion=0.0.0.5
    #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
    #AutoIt3Wrapper_Res_LegalCopyright=CC-NC-SA-BY Tarumes
    #AutoIt3Wrapper_Res_Language=1031
    #AutoIt3Wrapper_Run_Tidy=y
    #Tidy_Parameters=/tc 1 /gd /rel /reel
    #AutoIt3Wrapper_Run_Au3Stripper=y
    #Au3Stripper_Parameters=/rm
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    ;*****************************************
    ;BindMouse.au3 by Tarumes
    ;*****************************************
    ;
    ;// Check for Config File
    If FileExists("settings.ini") Then
    ;
    ;//Read Config from INI
    ConsoleWrite("FileExist" & @CRLF)
    Local $margin_top = IniRead("settings.ini", "Settings", "margin_top", "35")
    Local $margin_left = IniRead("settings.ini", "Settings", "margin_left", "15")
    Local $margin_right = IniRead("settings.ini", "Settings", "margin_right", "15")
    Local $margin_bottom = IniRead("settings.ini", "Settings", "margin_bottom", "15")
    Local $sleep = IniRead("settings.ini", "Settings", "Sleep", "20")
    
    Else
    ;
    ;//If File not Found Write it and set Default Config
    ConsoleWrite("FilNoteExist" & @CRLF)
    $hFileOpen = FileOpen("settings.ini", 1)
    FileWrite($hFileOpen, "[Settings]" & @CRLF)
    FileWrite($hFileOpen, "margin_top=35" & @CRLF)
    FileWrite($hFileOpen, "margin_left=15" & @CRLF)
    FileWrite($hFileOpen, "margin_right=15" & @CRLF)
    FileWrite($hFileOpen, "margin_bottom=15" & @CRLF)
    FileWrite($hFileOpen, "Sleep=20" & @CRLF)
    FileClose($hFileOpen)
    Local $margin_top = 35
    Local $margin_left = 15
    Local $margin_right = 15
    Local $margin_bottom = 15
    Local $sleep = 10 ;<--- Lower needs more CPU never set to 0 or Negative it will burn your CPU
    
    EndIf
    ;
    ;//Show Messagebox
    MsgBox(266304, "Hotkeys", "Pause Binding SHIFT + ALT + P" & @CRLF & "Exit Bind to Stardew Valley SHIFT + ALT + X", 30)
    ;*****************************************
    ;DONT TOUCH IF YOU NOT KNOW
    ;*****************************************
    Opt("MouseCoordMode", 0) ;1=absolute, 0=relative, 2=client) <-- 0 = Relative to Window
    ;//Set Hotkeys
    HotKeySet("+!p", "TogglePause") ; Shift-Alt-p
    HotKeySet("+!x", "Terminate") ; Shift-Alt-x
    ;//Variable to toggle Pause
    Global $gPaused = False
    ;//Dont blame me for this
    Local $top = $margin_top
    Local $left = $margin_left
    ;//Start While in endless loop
    While 1
    ;//Check for Window Title "Stardew Valley" and ignore "SMAPI Console Window"
    If WinActive("Stardew Valley") And Not WinActive("[CLASS:ConsoleWindowClass]") Then
      ;
      ;//Get Mouse Position
      Local $Mouse = MouseGetPos()
      ;//Get Active Window (only if Stardew Valley is active Windows)
      Local $wPos = WinGetPos("[ACTIVE]")
      ;//calculate right and bottom Border
      Local $right = $wPos[2] - $margin_right
      Local $bottom = $wPos[3] - $margin_bottom
      ;//Variable for Target Position
      Local $move = 0
      ;
      ;//Left Border
      If $Mouse[0] < $left Then
       $move = $left
       MouseMove($move, $Mouse[1], 1)
       ;
       ;//Top Border
      ElseIf $Mouse[1] < $top Then
       $move = $top
       MouseMove($Mouse[0], $move, 1)
       ;
       ;//Right Border
      ElseIf $Mouse[0] > $right Then
       $move = $right
       MouseMove($move, $Mouse[1], 1)
       ;
       ;//Bottom Border
      ElseIf $Mouse[1] > $bottom Then
       $move = $bottom
       MouseMove($Mouse[0], $move, 1)
    
      EndIf
    
    EndIf ;
    Sleep($sleep) ; <-- give CPU some Love
    WEnd
    ;
    ;//Function to Pause
    Func TogglePause()
    $gPaused = Not $gPaused
    While $gPaused
      Sleep(100)
      ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
    EndFunc   ;==>TogglePause
    ;
    ;//Function to Terminate
    Func Terminate()
    Exit
    EndFunc   ;==>Terminate
    
     

      Attached Files:

      Last edited: May 31, 2017

    Share This Page