#SingleInstance Force #Persistent DetectHiddenWindows, On ; Tray icon and menu definition ;Menu, TRAY, Icon, MuteOnHibernate.ico, 1, 1 Menu, TRAY, Tip, AutoHotkey Script for Arcade Controls ; Listen to the Windows power event "WM_POWERBROADCAST" (ID: 0x218): OnMessage(0x218, "func_WM_POWERBROADCAST") /* http://www.autohotkey.com/forum/topic21697.html */ /* This function is executed if the system sends a power event. Parameters wParam and lParam define the type of event: lParam: always 0 wParam: PBT_APMQUERYSUSPEND 0x0000 PBT_APMQUERYSTANDBY 0x0001 PBT_APMQUERYSUSPENDFAILED 0x0002 PBT_APMQUERYSTANDBYFAILED 0x0003 PBT_APMSUSPEND 0x0004 PBT_APMSTANDBY 0x0005 PBT_APMRESUMECRITICAL 0x0006 PBT_APMRESUMESUSPEND 0x0007 PBT_APMRESUMESTANDBY 0x0008 PBTF_APMRESUMEFROMFAILURE 0x00000001 PBT_APMBATTERYLOW 0x0009 PBT_APMPOWERSTATUSCHANGE 0x000A PBT_APMOEMEVENT 0x000B PBT_APMRESUMEAUTOMATIC 0x0012 Source: http://weblogs.asp.net/ralfw/archive/2003/09/09/26908.aspx */ func_WM_POWERBROADCAST(wParam, lParam) { ; wake up event If (lParam = 0 && wParam = 18) { Sleep, 5000 ; run keyWiz to write default key setup to arcade controller Run "C:\Program Files\KeyWiz Uploader3\KeyWiz_Uploader3.exe" /A /S /P B, C:\Program Files\KeyWiz Uploader3 Sleep, 2000 Run "E:\AtomicFE_v020Ult\AtoMic.exe" } Return } ; my Global vars atomicRunning = 0 mameRunning = 0 atariRunning = 0 emulatorRunning = 0 snesRunning = 0 /* UpdateStatus() - updates all variables so we know what out state is. */ UpdateStatus() { ; note all our global variables global atomicRunning, mameRunning, atariRunning, emulatorRunning, snesRunning Process, Exist, AtoMic.exe processPid = %Errorlevel% if processPid atomicRunning = 1 else atomicRunning = 0 emulatorRunning = 0 Process, Exist, MameUI32.exe processPid = %Errorlevel% if processPid { mameRunning = 1 emulatorRunning = 1 } else mameRunning = 0 Process, Exist, stella.exe processPid = %Errorlevel% if processPid { atariRunning = 1 emulatorRunning = 1 } else atariRunning = 0 Process, Exist, Zsnesw.exe snesPid = %Errorlevel% if snesPid { snesRunning = 1 emulatorRunning = 1 } else snesRunning = 0 Process, Exist, fceux.exe nesPid = %Errorlevel% Process, Exist, fusion.exe genesisPid = %Errorlevel% if nesPid or genesisPid emulatorRunning = 1 } /* handle SHA+Gold key: if Atomic isn't running, run it. if atomic is running if no emulators are running, close atomic and sleep if an emulator is running, close it if atari is running, close it with CTRL+Q if mame is running, close it with esc if any other emulator is running, close it with ALT+F4 */ ~F10:: UpdateStatus() if atariRunning { ; CTRL+Q to quit Send, {Control Down}q{Control Up} } else if mameRunning { ; http://www.autohotkey.com/forum/topic6887.html for more info ; directly kill process. couldn't get key presses to work :( ;Process, Close, MameUI32.exe ;Send {F10} } else if snesRunning { ; alt+F4 doesn't work from here for some reason ;Process, Close, Zsnesw.exe ; zsnes is configured to exit on F10, do nothing } ; kill whatever emulator is running, if one is else if emulatorRunning { Send, {Alt Down}{F4}{Alt Up} } ; sitting in atomic, we want to kill atomic and sleep else if atomicRunning and emulatorRunning = 0 { ; Atomic is already running, shut it down Process, Close, AtoMic.exe ; and put the computer to sleep Sleep, 500 DllCall("PowrProf\SetSuspendState", "int", 0, "int", 1, "int", 0) } else if atomicRunning = 0 { ; run atomic Run "E:\AtomicFE_v020Ult\AtoMic.exe" } Return F11:: UpdateStatus() if mameRunning { ;NON WORKING - I used cocktail mode instead ;WinWait, MAME: Donkey Kong (US set 1) [dkong], ;IfWinNotActive, MAME: Donkey Kong (US set 1) [dkong], , WinActivate, MAME: Donkey Kong (US set 1) [dkong], ;WinWaitActive, MAME: Donkey Kong (US set 1) [dkong], ;Send, {TAB}{UP}{UP}{UP}{ENTER}{DOWN}{DOWN}{DOWN}{RIGHT}{RIGHT}{UP}{UP}{UP}{UP}{ENTER}{DOWN}{DOWN}{ENTER} ; send keys to rotate display ;Send, {TAB}{UP}{UP}{UP}{ENTER}{DOWN}{DOWN}{DOWN}{RIGHT}{RIGHT}{UP}{UP}{UP}{UP}{ENTER}{DOWN}{DOWN}{ENTER} } else if emulatorRunning { ; send CTRL+ALT+1 Send, {Alt Down}{Control Down}1{Alt Up}{Control Up} } Return /* handle SHA+P1 key, rotate display to player 2 if atomic is not running, do nothing if an emulator is running, rotate display to P2 if mame is running, go through key presses to navigate rotate menu if any other emulator is running, send ALT+SHIFT+2 */ F12:: UpdateStatus() if mameRunning { ;NON WORKING - I used cocktail mode instead ; send keys to rotate display ;Send, {TAB}{UP}{UP}{UP}{ENTER}{DOWN}{DOWN}{DOWN}{RIGHT}{RIGHT}{UP}{UP}{UP}{UP}{ENTER}{DOWN}{DOWN}{ENTER} } else if emulatorRunning { ; send CTRL+ALT+2 Send, {Alt Down}{Control Down}2{Alt Up}{Control Up} } Return F4:: ; send an alt-tab, in cases where something went awry in startup Send, {Alt Down}{Tab}{Alt Up} Return F3:: ; send an alt-tab-tab, in cases where something went awry in startup Send, {Alt Down}{Tab}{Tab}{Alt Up} Return ; main three buttons on the arcade controls for p1, DEFAULT config ; If the arcade buttons aren't mapped correctly, use this to set them ^!Space:: Run "C:\Program Files\KeyWiz Uploader3\KeyWiz_Uploader3.exe" /A /S /P B, C:\Program Files\KeyWiz Uploader3 return