Advertisement
Guest User

Untitled

a guest
Sep 1st, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.47 KB | None | 0 0
  1. #!c:/python27/python.exe -u
  2.  
  3. #BY: Brandon "Zhurai" Fu
  4.  
  5. #REQUIRES:
  6. #- Python 2.7 -- maybe others, didn't try
  7. #- Autoit (latest) -- make sure it's the same bit as Python (even if it complains about 64bit) and install the COM
  8. #- Python for Windows extensions for Python 2.7 -- http://sourceforge.net/projects/pywin32/files/pywin32/Build%20217/
  9.  
  10. import codecs
  11. import win32api
  12. import win32con
  13. import win32com.client
  14. import win32gui
  15. import win32process
  16. import time
  17. from _winreg import *
  18.  
  19. #
  20. # Notes for which button to which
  21. #
  22. #               Goes like this
  23. #             | Button 1 | Button 5 | Button 9
  24. #             | Button 2 | Button 6 | Button 10
  25. #             | Button 3 | Button 7 | Button 11
  26. #             | Button 4 | Button 8 | Button 12
  27. #
  28.  
  29. # sanity purposes
  30. print "DEBUG: SceneSwitcher: Created by Zhurai"
  31. print "DEBUG: SceneSwitcher: Setting Variables"
  32. autoit = win32com.client.Dispatch("AutoItX3.Control")
  33. detect=win32api.GetKeyState
  34. w=win32gui
  35. aReg = ConnectRegistry(None,HKEY_CURRENT_USER)
  36. aKey = OpenKey(aReg, r"SOFTWARE\Razer\StarCraft2")
  37. stream = "XSplit Broadcaster"
  38. stream2="Streaming Live"
  39.  
  40. isdesktop=1
  41. ismtgo=0
  42. ismahjong=0
  43. isosu=0
  44. issc2=0
  45. issc2ingame=0
  46. issc2ingame2=0
  47. isbw=0
  48. isother=0
  49. isgw2=0
  50. isgamebroadcasterhd=0 #not programming this in yet
  51.  
  52. # assume we start in the desktop...and hide XSplit
  53. autoit.ControlClick(stream,"","[CLASSNN:Button1]")
  54. autoit.ControlClick(stream2,"","[CLASSNN:Button1]")
  55. print "DEBUG: XSplit: Switched to Desktop"
  56. autoit.WinSetState("SceneSwitcher","",6);
  57. print "DEBUG: SceneSwitcher: Hid Console"
  58.  
  59. # start loop of checking the window/etc
  60. while True:
  61.     # SC2: Detect if we are in the menu or ingame
  62.     sc2reg = EnumValue(aKey,0)
  63.     if (sc2reg[1] == 1):
  64.         # we are in game
  65.         print "DEBUG: SC2: We Are Ingame!"
  66.         issc2ingame=1
  67.     else:
  68.         # we are in the menu
  69.         issc2ingame=0
  70.    
  71.     window = w.GetWindowText (w.GetForegroundWindow())
  72.     print "%s %s%s%s" % ("DEBUG: SceneSwitcher: ","'",window,"'") # Debug
  73.    
  74.     if window == "osu!":
  75.         # Now in Osu!
  76.         print "DEBUG: Osu!: Active Window"
  77.        
  78.         # send the keys with another if statement to not have an infinite loop..
  79.         if isosu == 0:
  80.             autoit.ControlClick(stream,"","[CLASSNN:Button5]")
  81.             autoit.ControlClick(stream2,"","[CLASSNN:Button5]")
  82.             print "DEBUG: XSplit: Switched to Osu!"
  83.  
  84.         # set the stuff so the program doesn't get confused
  85.         isdesktop=0
  86.         ismtgo=0
  87.         ismahjong=0
  88.         isosu=1
  89.         issc2=0
  90.         issc2ingame=0
  91.         issc2ingame2=0
  92.         isbw=0
  93.         isother=0
  94.         isgw2=0
  95.         isgamebroadcasterhd=0
  96.                
  97.     elif window == "Magic Online":
  98.         # Now in MTGO!
  99.         print "DEBUG: Magic Online: Active Window"
  100.  
  101.         # Maximize Window
  102.        
  103.         # send the keys with another if statement to not have an infinite loop..
  104.         if ismtgo == 0:
  105.             autoit.ControlClick(stream,"","[CLASSNN:Button3]")
  106.             autoit.ControlClick(stream2,"","[CLASSNN:Button3]")
  107.             print "DEBUG: XSplit: Switched to MTGO"
  108.            
  109.         # set the stuff so the program doesn't get confused
  110.         isdesktop=0
  111.         ismtgo=1
  112.         ismahjong=0
  113.         isosu=0
  114.         issc2=0
  115.         issc2ingame=0
  116.         issc2ingame2=0
  117.         isbw=0
  118.         isother=0
  119.         isgw2=0
  120.         isgamebroadcasterhd=0
  121.  
  122.     elif window == "Brood War":
  123.         # Now in SC:BW!
  124.         print "DEBUG: Brood War: Active Window"
  125.        
  126.         # send the keys with another if statement to not have an infinite loop..
  127.         if isbw == 0:
  128.             autoit.ControlClick(stream,"","[CLASSNN:Button7]")
  129.             autoit.ControlClick(stream2,"","[CLASSNN:Button7]")
  130.             print "DEBUG: XSplit: Switched to Brood War"
  131.  
  132.         # Alt+F commands to send
  133.        
  134.         # set the stuff so the program doesn't get confused
  135.         isdesktop=0
  136.         ismtgo=0
  137.         ismahjong=0
  138.         isosu=0
  139.         issc2=0
  140.         issc2ingame=0
  141.         issc2ingame2=0
  142.         isbw=1
  143.         isother=0
  144.         isgw2=0
  145.         isgamebroadcasterhd=0
  146.  
  147.     elif window == "StarCraft II" or window.decode('cp932') == u'\u661f\u6d77\u722d\u9738II':
  148.         # Now in SC2! (En, Tw)
  149.         print "DEBUG: StarCraft 2: Active Window"
  150.  
  151.         # detection if the game starts/ends while you're still tabbed in
  152.         if issc2 == 1:
  153.             # and we have been in the menu, but we haven't switched it yet
  154.             if issc2ingame ==0 and issc2ingame2==1:
  155.                 # switch!
  156.                 autoit.ControlClick(stream,"","[CLASSNN:Button2]")
  157.                 autoit.ControlClick(stream2,"","[CLASSNN:Button2]")
  158.                 print "DEBUG: XSplit: Switched to SC2 Menu"
  159.                 issc2ingame ==0
  160.             # and we have been ingame but it hasn't switched yet
  161.             elif issc2ingame ==1 and issc2ingame2==0:
  162.                 # switch!
  163.                 autoit.ControlClick(stream,"","[CLASSNN:Button6]")
  164.                 autoit.ControlClick(stream2,"","[CLASSNN:Button6]")
  165.                 print "DEBUG: XSplit: Switched to SC2 InGame"
  166.                 issc2ingame ==1
  167.                    
  168.         # send the keys with another if statement to not have an infinite loop..
  169.         if issc2 == 0:
  170.             # we are ingame
  171.             if issc2ingame == 1:
  172.                 autoit.ControlClick(stream,"","[CLASSNN:Button6]")
  173.                 autoit.ControlClick(stream2,"","[CLASSNN:Button6]")
  174.                 print "DEBUG: XSplit: Switched to SC2 InGame"
  175.                 issc2ingame ==1
  176.             # we are in the menu
  177.             elif issc2ingame == 0:
  178.                 autoit.ControlClick(stream,"","[CLASSNN:Button2]")
  179.                 autoit.ControlClick(stream2,"","[CLASSNN:Button2]")
  180.                 print "DEBUG: XSplit: Switched to SC2 Menu"
  181.                 issc2ingame ==0
  182.          
  183.         # set the stuff so the program doesn't get confused
  184.         isdesktop=0
  185.         ismtgo=0
  186.         ismahjong=0
  187.         isosu=0
  188.         issc2=1
  189.         isbw=0
  190.         isother=0
  191.         isgw2=0
  192.         isgamebroadcasterhd=0
  193.        
  194.     elif window == "THIS ISNT WORKING ATM AS UNICODE COMPARISON IS ANNOYING ME": # Mahjong
  195.                 # Programs:  add the other ones: web tenhou, flash, mahjongtime, janryumon
  196.         # Now in Mahjong
  197.         print "DEBUG: Mahjong: Active Window"
  198.        
  199.         # Maximize window
  200.        
  201.         # send the keys with another if statement to not have an infinite loop..
  202.         if isbw == 0:
  203.             autoit.ControlClick(stream,"","[CLASSNN:Button4]")
  204.             autoit.ControlClick(stream2,"","[CLASSNN:Button4]")
  205.             print "DEBUG: XSplit: Switched to Mahjong"
  206.            
  207.         # set the stuff so the program doesn't get confused
  208.         isdesktop=0
  209.         ismtgo=0
  210.         ismahjong=1
  211.         isosu=0
  212.         issc2=0
  213.         issc2ingame=0
  214.         issc2ingame2=0
  215.         isbw=0
  216.         isother=0
  217.         isgw2=0
  218.         isgamebroadcasterhd=0
  219.  
  220.     elif window == "Guild Wars 2": # Guild Wars 2
  221.         # Now in Guild Wars 2
  222.         print "DEBUG: GW2: Active Window"
  223.        
  224.         # send the keys with another if statement to not have an infinite loop..
  225.         if isbw == 0:
  226.             autoit.ControlClick(stream,"","[CLASSNN:Button9]")
  227.             autoit.ControlClick(stream2,"","[CLASSNN:Button9]")
  228.             print "DEBUG: XSplit: Switched to Guild Wars 2"
  229.            
  230.         # set the stuff so the program doesn't get confused
  231.         isdesktop=0
  232.         ismtgo=0
  233.         ismahjong=0
  234.         isosu=0
  235.         issc2=0
  236.         issc2ingame=0
  237.         issc2ingame2=0
  238.         isbw=0
  239.         isother=0
  240.         isgw2=1
  241.         isgamebroadcasterhd=0          
  242.                
  243.     elif window == "Task Switching":
  244.         # do nothing. At All.
  245.         istaskswitch=1
  246.                
  247.     elif window == stream or stream2 in window:
  248.         # do nothing. At All.
  249.         isxsplit=1
  250.                
  251.     else:
  252.         if isdesktop==0:
  253.             # tabbed out of the above programs
  254.             autoit.ControlClick(stream,"","[CLASSNN:Button1]")
  255.             autoit.ControlClick(stream2,"","[CLASSNN:Button1]")
  256.             print "DEBUG: XSplit: Switched to Desktop"
  257.         isdesktop=1
  258.         ismtgo=0
  259.         ismahjong=0
  260.         isosu=0
  261.         issc2=0
  262.         issc2ingame=0
  263.         issc2ingame2=0
  264.         isbw=0
  265.         isother=0
  266.         isgw2=0
  267.         isgamebroadcasterhd=0
  268.  
  269.     time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement