Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. ;;This program will monitor mame64.exe title window to match the game name and run Ultimarcs joytray.exe to set either 4 way or 8 way controls
  2. ;;It also will kill mame64.exe after 3 min of inactivity
  3. ;;This was meant to be used in conjuction with launchbox/bigbox.
  4.  
  5. ;;joycontrol.txt should be formatted like this line by line:
  6. ;;gamename,X
  7. ;;I.E: simpsons,8
  8. ;;Game name does not need to be exact, program will look for keywords. X should be either 4 or 8 to denote 4 or 8 way respectively
  9. ;;"C:\Programfiles\JoyTray whatever and where ever it installs to" from ultimarc should be set in windows PATH.
  10.  
  11. #include <MsgBoxConstants.au3>
  12. #include <FileConstants.au3>
  13. #include <WinAPIFiles.au3>
  14. #include <File.au3>
  15. #include <Timers.au3>
  16.  
  17. Opt("TrayAutoPause", 0)
  18.  
  19.  
  20. $file = "joycontrol.txt"
  21. FileOpen($file, 0)
  22. Local $iLength
  23. Local $set = 0
  24.  
  25.  
  26.  
  27. While 1
  28.  
  29.  
  30. Local $hWnd = ("[CLASS:MAME]")
  31. Local $iPID = WinGetProcess($hWnd)
  32.  
  33.  
  34. Local $iIdleTime = _Timer_GetIdleTime()
  35.  
  36. If $iIdleTime > 180000 And ProcessExists("mame64.exe") Then
  37. ProcessClose($iPID)
  38.  
  39. EndIf
  40.  
  41.  
  42. If ProcessExists("mame64.exe") and $set = 0 Then
  43.  
  44. $sMameWindowTitle = WinGetTitle('[CLASS:MAME]')
  45.  
  46.  
  47. SetMode()
  48.  
  49. EndIf
  50.  
  51.  
  52. If Not ProcessExists("mame64.exe") Then
  53.  
  54. HotKeySet("{ESC}", "disable_esc")
  55. $set = 0
  56. ConsoleWrite("Setting mode as unset" & @CRLF)
  57.  
  58. Else
  59. HotKeySet("{ESC}")
  60.  
  61.  
  62. EndIf
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. WEnd
  70.  
  71.  
  72. Func SetMode()
  73.  
  74.  
  75.  
  76. For $i = 1 to _FileCountLines($file)
  77. $line = FileReadLine($file, $i)
  78.  
  79. Local $iLength = StringLen($line)
  80. $sMameWindowTitleTrim = StringTrimRight($line, 2)
  81.  
  82.  
  83. $sSearch = StringinStr($sMameWindowTitle, $sMameWindowTitleTrim)
  84.  
  85.  
  86. if $sSearch > 0 Then
  87.  
  88. Local $iLength = StringLen($line)
  89. $sRom = FileReadLine ($file, $i)
  90.  
  91. Local $sMode = StringTrimLeft($sRom, ($iLength - 1))
  92.  
  93. $set = 1
  94. ConsoleWrite("Setting mode as: " & $sMode)
  95.  
  96. If $sMode = 4 Then
  97. Run(@ComSpec & ' /k ' & 'JoyTray.exe -servo joy4way',"",@SW_HIDE)
  98. EndIf
  99. If $sMode = 8 Then
  100. Run(@ComSpec & ' /k ' & 'JoyTray.exe -servo joy8way',"",@SW_HIDE)
  101. EndIf
  102.  
  103.  
  104. ExitLoop
  105.  
  106. EndIf
  107.  
  108.  
  109. Next
  110.  
  111.  
  112.  
  113.  
  114. EndFunc
  115.  
  116. func disable_esc()
  117. Send("")
  118. Sleep(100)
  119. EndFunc
  120.  
  121.  
  122.  
  123. ;;True programmers don't comment their code
  124. ;;If it was hard to write, then it should be hard to read.
  125. ;;Also I'm lazy.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement