Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!c:/python27/python.exe -u
- #BY: Brandon "Zhurai" Fu
- #REQUIRES:
- #- Python 2.7 -- maybe others, didn't try
- #- Autoit (latest) -- make sure it's the same bit as Python (even if it complains about 64bit) and install the COM
- #- Python for Windows extensions for Python 2.7 -- http://sourceforge.net/projects/pywin32/files/pywin32/Build%20217/
- import codecs
- import win32api
- import win32con
- import win32com.client
- import win32gui
- import win32process
- import time
- from _winreg import *
- #
- # Notes for which button to which
- #
- # Goes like this
- # | Button 1 | Button 5 | Button 9
- # | Button 2 | Button 6 | Button 10
- # | Button 3 | Button 7 | Button 11
- # | Button 4 | Button 8 | Button 12
- #
- # sanity purposes
- print "DEBUG: SceneSwitcher: Created by Zhurai"
- print "DEBUG: SceneSwitcher: Setting Variables"
- autoit = win32com.client.Dispatch("AutoItX3.Control")
- detect=win32api.GetKeyState
- w=win32gui
- aReg = ConnectRegistry(None,HKEY_CURRENT_USER)
- aKey = OpenKey(aReg, r"SOFTWARE\Razer\StarCraft2")
- stream = "XSplit Broadcaster"
- stream2="Streaming Live"
- isdesktop=1
- ismtgo=0
- ismahjong=0
- isosu=0
- issc2=0
- issc2ingame=0
- issc2ingame2=0
- isbw=0
- isother=0
- isgw2=0
- isgamebroadcasterhd=0 #not programming this in yet
- # assume we start in the desktop...and hide XSplit
- autoit.ControlClick(stream,"","[CLASSNN:Button1]")
- autoit.ControlClick(stream2,"","[CLASSNN:Button1]")
- print "DEBUG: XSplit: Switched to Desktop"
- autoit.WinSetState("SceneSwitcher","",6);
- print "DEBUG: SceneSwitcher: Hid Console"
- # start loop of checking the window/etc
- while True:
- # SC2: Detect if we are in the menu or ingame
- sc2reg = EnumValue(aKey,0)
- if (sc2reg[1] == 1):
- # we are in game
- print "DEBUG: SC2: We Are Ingame!"
- issc2ingame=1
- else:
- # we are in the menu
- issc2ingame=0
- window = w.GetWindowText (w.GetForegroundWindow())
- print "%s %s%s%s" % ("DEBUG: SceneSwitcher: ","'",window,"'") # Debug
- if window == "osu!":
- # Now in Osu!
- print "DEBUG: Osu!: Active Window"
- # send the keys with another if statement to not have an infinite loop..
- if isosu == 0:
- autoit.ControlClick(stream,"","[CLASSNN:Button5]")
- autoit.ControlClick(stream2,"","[CLASSNN:Button5]")
- print "DEBUG: XSplit: Switched to Osu!"
- # set the stuff so the program doesn't get confused
- isdesktop=0
- ismtgo=0
- ismahjong=0
- isosu=1
- issc2=0
- issc2ingame=0
- issc2ingame2=0
- isbw=0
- isother=0
- isgw2=0
- isgamebroadcasterhd=0
- elif window == "Magic Online":
- # Now in MTGO!
- print "DEBUG: Magic Online: Active Window"
- # Maximize Window
- # send the keys with another if statement to not have an infinite loop..
- if ismtgo == 0:
- autoit.ControlClick(stream,"","[CLASSNN:Button3]")
- autoit.ControlClick(stream2,"","[CLASSNN:Button3]")
- print "DEBUG: XSplit: Switched to MTGO"
- # set the stuff so the program doesn't get confused
- isdesktop=0
- ismtgo=1
- ismahjong=0
- isosu=0
- issc2=0
- issc2ingame=0
- issc2ingame2=0
- isbw=0
- isother=0
- isgw2=0
- isgamebroadcasterhd=0
- elif window == "Brood War":
- # Now in SC:BW!
- print "DEBUG: Brood War: Active Window"
- # send the keys with another if statement to not have an infinite loop..
- if isbw == 0:
- autoit.ControlClick(stream,"","[CLASSNN:Button7]")
- autoit.ControlClick(stream2,"","[CLASSNN:Button7]")
- print "DEBUG: XSplit: Switched to Brood War"
- # Alt+F commands to send
- # set the stuff so the program doesn't get confused
- isdesktop=0
- ismtgo=0
- ismahjong=0
- isosu=0
- issc2=0
- issc2ingame=0
- issc2ingame2=0
- isbw=1
- isother=0
- isgw2=0
- isgamebroadcasterhd=0
- elif window == "StarCraft II" or window.decode('cp932') == u'\u661f\u6d77\u722d\u9738II':
- # Now in SC2! (En, Tw)
- print "DEBUG: StarCraft 2: Active Window"
- # detection if the game starts/ends while you're still tabbed in
- if issc2 == 1:
- # and we have been in the menu, but we haven't switched it yet
- if issc2ingame ==0 and issc2ingame2==1:
- # switch!
- autoit.ControlClick(stream,"","[CLASSNN:Button2]")
- autoit.ControlClick(stream2,"","[CLASSNN:Button2]")
- print "DEBUG: XSplit: Switched to SC2 Menu"
- issc2ingame ==0
- # and we have been ingame but it hasn't switched yet
- elif issc2ingame ==1 and issc2ingame2==0:
- # switch!
- autoit.ControlClick(stream,"","[CLASSNN:Button6]")
- autoit.ControlClick(stream2,"","[CLASSNN:Button6]")
- print "DEBUG: XSplit: Switched to SC2 InGame"
- issc2ingame ==1
- # send the keys with another if statement to not have an infinite loop..
- if issc2 == 0:
- # we are ingame
- if issc2ingame == 1:
- autoit.ControlClick(stream,"","[CLASSNN:Button6]")
- autoit.ControlClick(stream2,"","[CLASSNN:Button6]")
- print "DEBUG: XSplit: Switched to SC2 InGame"
- issc2ingame ==1
- # we are in the menu
- elif issc2ingame == 0:
- autoit.ControlClick(stream,"","[CLASSNN:Button2]")
- autoit.ControlClick(stream2,"","[CLASSNN:Button2]")
- print "DEBUG: XSplit: Switched to SC2 Menu"
- issc2ingame ==0
- # set the stuff so the program doesn't get confused
- isdesktop=0
- ismtgo=0
- ismahjong=0
- isosu=0
- issc2=1
- isbw=0
- isother=0
- isgw2=0
- isgamebroadcasterhd=0
- elif window == "THIS ISNT WORKING ATM AS UNICODE COMPARISON IS ANNOYING ME": # Mahjong
- # Programs: add the other ones: web tenhou, flash, mahjongtime, janryumon
- # Now in Mahjong
- print "DEBUG: Mahjong: Active Window"
- # Maximize window
- # send the keys with another if statement to not have an infinite loop..
- if isbw == 0:
- autoit.ControlClick(stream,"","[CLASSNN:Button4]")
- autoit.ControlClick(stream2,"","[CLASSNN:Button4]")
- print "DEBUG: XSplit: Switched to Mahjong"
- # set the stuff so the program doesn't get confused
- isdesktop=0
- ismtgo=0
- ismahjong=1
- isosu=0
- issc2=0
- issc2ingame=0
- issc2ingame2=0
- isbw=0
- isother=0
- isgw2=0
- isgamebroadcasterhd=0
- elif window == "Guild Wars 2": # Guild Wars 2
- # Now in Guild Wars 2
- print "DEBUG: GW2: Active Window"
- # send the keys with another if statement to not have an infinite loop..
- if isbw == 0:
- autoit.ControlClick(stream,"","[CLASSNN:Button9]")
- autoit.ControlClick(stream2,"","[CLASSNN:Button9]")
- print "DEBUG: XSplit: Switched to Guild Wars 2"
- # set the stuff so the program doesn't get confused
- isdesktop=0
- ismtgo=0
- ismahjong=0
- isosu=0
- issc2=0
- issc2ingame=0
- issc2ingame2=0
- isbw=0
- isother=0
- isgw2=1
- isgamebroadcasterhd=0
- elif window == "Task Switching":
- # do nothing. At All.
- istaskswitch=1
- elif window == stream or stream2 in window:
- # do nothing. At All.
- isxsplit=1
- else:
- if isdesktop==0:
- # tabbed out of the above programs
- autoit.ControlClick(stream,"","[CLASSNN:Button1]")
- autoit.ControlClick(stream2,"","[CLASSNN:Button1]")
- print "DEBUG: XSplit: Switched to Desktop"
- isdesktop=1
- ismtgo=0
- ismahjong=0
- isosu=0
- issc2=0
- issc2ingame=0
- issc2ingame2=0
- isbw=0
- isother=0
- isgw2=0
- isgamebroadcasterhd=0
- time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement