Advertisement
Guest User

getkey.ahk

a guest
Feb 18th, 2016
3,935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;   Copyright 2014 colingg (colin.gg)
  2. ;
  3. ;   Licensed under the Apache License, Version 2.0 (the "License");
  4. ;   you may not use this file except in compliance with the License.
  5. ;   You may obtain a copy of the License at
  6. ;
  7. ;       http://www.apache.org/licenses/LICENSE-2.0
  8. ;
  9. ;  Unless required by applicable law or agreed to in writing, software
  10. ;  distributed under the License is distributed on an "AS IS" BASIS,
  11. ;  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. ;  See the License for the specific language governing permissions and
  13. ;  limitations under the License.
  14.  
  15.  
  16.  
  17. ;Variables>     http://ahkscript.org/docs/Variables.htm#Cursor
  18. ;Gendocs >      https://github.com/fincs/GenDocs
  19. ;OutPutDebug    http://www.autohotkey.com/docs/commands/OutputDebug.htm
  20. /*!
  21.     Script: Steam Bulk Key Activator 1.0
  22.         This script/macro allows you to activate steam keys in bulk,
  23.         up to 25 keys at once (steam limit)
  24.  
  25.     Author: colingg
  26.     License: Apache License, Version 2.0
  27. */
  28. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  29. #Warn All, Off  ; Disable warnings (error dialog boxes being shown to user)
  30. #singleinstance force ;force looping
  31. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  32. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  33. ;#----------------------------------------- End of header ------------------------------------------------------
  34. ;#----------------------------------------- Methods / functions below  -----------------------------------------
  35.  
  36. ;general methods/functions
  37.  
  38. steam_activate_key(key){                    ;method that takes a string variable (the key) and places it into the key box of steam activator window
  39.     if(key = ""){ ;check to make sure key is not empty
  40.         applog("we got an empty key ? ignoring this one")
  41.         return
  42.     }
  43.     applog("[start of a new key]")
  44.  
  45.     FormatTime, Time,, dd/MM/yyyy HH:mm:ss tt
  46.     log_to_file("`n[" . Time . "] " . "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ",false)
  47.     log_to_file("`n[" . Time . "] " . "'key' =>" . " '" . key . "'",false)
  48.     steam_close_all()
  49.     steam_open_activation_window()
  50.     steam_move_window()
  51.     steam_click_next()
  52.     steam_click_next()
  53.     steam_activate_product_code_field()
  54.     steam_send_input(key)
  55.     steam_click_next()
  56.     steam_wait_until_done()
  57.     if(steam_check_if_key_worked()){
  58.         applog("[sucessfull] key activated without problems !")
  59.         log_to_file(", 'success' => 'true'",false)
  60.         ;log_to_file("      <---- Activated",false)
  61.     }else{
  62.         applog("[faillure] key failed to activate !")
  63.         log_to_file(", 'success' => 'false' ",false)
  64.         ;log_to_file("      <---- Failed",false)
  65.  
  66.     }
  67.     applog("[end of this key]")
  68.     return
  69. }
  70.  
  71. ;mouse and keyboard interactions
  72.  
  73. steam_click_next(){                         ;click the next button
  74.     steam_activate_window()
  75.     MouseClick, left,  320,  375 ;click next
  76.     applog("> clicked next      [activation]")
  77.     Sleep,100
  78.     return
  79. }
  80. steam_click_cancel(){                       ;click the cancel button
  81.     steam_activate_window()
  82.     MouseClick, left,  422,  375 ;click cancel.
  83.     applog("> clicked cancel    [activation]")
  84.     Sleep,100
  85.     return
  86. }
  87. steam_click_back(){                         ;click the back button
  88.     steam_activate_window()
  89.     MouseClick, left,  212,  375 ;click back
  90.     applog("> clicked back      [activation]")
  91.     Sleep,100
  92.     return
  93. }
  94. steam_click_print(){                        ;click the print button
  95.     steam_activate_window()
  96.     MouseClick, left,  221,  407 ;click print
  97.     applog("> clicked print     [activation]")
  98.     Sleep,100
  99.     return
  100. }
  101. steam_install_click_back(){                 ;install window click back
  102.     steam_activate_install()
  103.     MouseClick, left,  212,  375 ;click back
  104.     applog("> clicked back      [install]")
  105.     Sleep,100
  106.     return
  107.  
  108. }
  109. steam_install_click_cancel(){               ;install window click cancel
  110.     steam_activate_install()
  111.     MouseClick, left,  422,  375 ;click cancel.
  112.     applog("> clicked cancel    [install]")
  113.     Sleep,100
  114.     return
  115. }
  116. steam_install_click_next(){                 ;install window click next
  117.     steam_activate_install()
  118.     MouseClick, left,  320,  375 ;click next
  119.     applog("> clicked next      [install]")
  120.     Sleep,100
  121.     return
  122. }
  123. steam_activate_product_code_field(){        ;activate the product code field
  124.     steam_activate_window()
  125.     MouseClick, left,  40,  190  ;click Product code field
  126.     applog("> clicked product code field")
  127.     Sleep, 100
  128.     return
  129. }
  130. steam_send_input(input){                    ;send text to the steam window
  131.     steam_activate_window()
  132.     SendInput {Raw}%input%
  133.     applog("> sent input to steam activation window")
  134.     Sleep,100
  135.     return
  136. }
  137.  
  138. ;window interactions
  139.  
  140. steam_activate_window(){                    ;activate the steam activation window
  141.     WinWait, Product Activation, ;wait for the activation window to pop up
  142.     IfWinNotActive, Product Activation, , WinActivate, Product Activation, ;if not active make active
  143.     WinWaitActive, Product Activation, ;wait until active
  144.     applog("waited and activated the steam activation window")
  145.     Sleep, 100 ;let windows recover a bit ! you slow piece of shit !
  146. }
  147. steam_activate_install(){                   ;activate the installer window
  148.     WinWait, Install -,
  149.     IfWinNotActive, Install -, , WinActivate, Install -,
  150.     WinWaitActive, Install -,
  151.     applog("waited for install window and activated it")
  152.     Sleep,100
  153. }
  154. steam_wait_until_done(){                    ;steam working handler
  155.     ;we need to wait for steam to stop working before we continue
  156.     applog("steam is working hold on ...")
  157.     Sleep,1000
  158.     WinWaitNotActive,Steam - Working
  159.     applog("steam is done working !")
  160.     ;steam stopped freezing ! we can continue
  161. }
  162. steam_move_window(){                        ;move the steam activation window
  163.     steam_activate_window()
  164.     WinMove, 0, 0 ;lets move the window to the left.
  165.     applog("moved steam activation window to 0,0")
  166.     Sleep,100
  167.     return
  168. }
  169. steam_open_activation_window(){             ;steam open the activation window
  170.     Run steam://open/activateproduct
  171.     applog("activated steam url to open activation window")
  172.     Sleep,100
  173.     return
  174. }
  175. steam_close_all(){                          ;this will close the activation window (it should not be open in the first place !)
  176.     applog("requested to close all activation windows (and print)")
  177.     IfWinExist,Product Activation,
  178.     {
  179.         applog("Activation window exists !")
  180.         steam_activate_window()
  181.         steam_click_back() ;click back 2 times to make sure we can cancel.
  182.         steam_click_back()
  183.         steam_click_cancel()
  184.         WinKill,Product Activation,
  185.         applog("closed the activation window")
  186.         Sleep,1000
  187.     }
  188.     IfWinExist,Install -,
  189.     {
  190.         applog("Install window exists!")
  191.         steam_activate_install()
  192.         ;cant use steam click,need installer clicks
  193.         steam_install_click_cancel()
  194.         WinKill,Install -,
  195.         applog("Activated the install window and clicked cancel")
  196.         Sleep,1000
  197.  
  198.     }
  199.     IfWinExist,Print,
  200.     {
  201.         applog("Print is open, closing it")
  202.         WinKill,Print,
  203.         Sleep,1000
  204.     }
  205.     return
  206.  
  207. }
  208. steam_check_if_key_worked(){                ;check if steam key worked
  209.     applog("we need to check if the key worked")
  210.     if(steam_check_invalid_or_too_many_attempts()){
  211.         applog("product code invalid or to many key tries")
  212.         ;Steam is whining (to many keys tries, or product code is invalid)
  213.         steam_click_cancel()
  214.         return false
  215.     }else{
  216.         applog("steam reports that our key is valid")
  217.         ;steam is happy !
  218.         ;make a difference between existing product and new product.
  219.         ;we need to press the print button & close that window again
  220.         applog("checking if this is a new product")
  221.         steam_click_print()
  222.         if(is_print_window()){
  223.             applog("[new product] we activated a new product")
  224.             log_to_file(", 'new product' => 'true'",false)
  225.             ;this means there is a print window & we closed it.
  226.         }else{
  227.             applog("[duplicate product] we activated a duplicate product")
  228.             log_to_file(", 'new product' => 'false'",false)
  229.             ;this means there is a print window & we closed it.
  230.         }
  231.         steam_click_next() ;we click next (past print screen)
  232.         applog("now we need to check if we are on the install screen")
  233.         ;in order to see if they key worked we need to check if we are on the install screen, if we are press cancel & report that the key worked
  234.         steam_check_if_on_install_screen()
  235.         steam_install_click_cancel()
  236.  
  237.     }
  238. }
  239. steam_check_invalid_or_too_many_attempts(){ ;check if steam is angry at us
  240.     steam_activate_window()
  241.     MouseMove, 61,  207 ;move mouse to the invalid link
  242.     applog("moved mouse to check if there is an invalid link")
  243.     Sleep,100
  244.     If(A_Cursor = "Unknown"){
  245.         applog("key is bad")
  246.         return true
  247.     }else{
  248.         applog("key is good")
  249.         return false
  250.     }
  251. }
  252. steam_check_if_on_install_screen(){         ;check if we are on the install screen
  253.     applog("checking if we are on the install window")
  254.     ;steam_activate_window() <--- does not work, because title changed
  255.     steam_activate_install()
  256.     WinMove, 100, 100 ;lets move the window to the left.
  257.     applog("moved install window to 100,100")
  258.     Sleep,100
  259.     WinGetTitle, WindowTitle,
  260.     StringTrimLeft,gameTitle,WindowTitle,10
  261.     applog("adding game title to key log")
  262.     log_to_file(", 'game' => '" . gameTitle . "'",false)
  263. }
  264. is_print_window(){                          ;way to check if we have a new product or a duplicate
  265.     applog("waiting 5 seconds for the print window to pop up")
  266.     WinWait, Print,,5 ;wait 5 seconds.
  267.     if ErrorLevel
  268.     {
  269.         applog("did not get a print window within 5 seconds")
  270.         return false
  271.     }else{
  272.         IfWinNotActive, Print, WinActivate, Print,
  273.         WinWaitActive, Print,
  274.         WinKill,Print,
  275.         applog("Print window was open, we closed it")
  276.         Sleep,100
  277.         return true
  278.     }
  279. }
  280. ;generic functions here
  281.  
  282. log_to_file(text,newline){                  ;log to the keys file.
  283.     if(newline){
  284.         FileAppend,%text%`n, %A_WorkingDir%\activation.log
  285.         return
  286.     }else{
  287.         FileAppend,%text%, %A_WorkingDir%\activation.log
  288.         return
  289.     }
  290. }
  291. applog(text){                               ;log to the application file
  292.     FormatTime, Time,, dd/MM/yyyy HH:mm:ss tt
  293.     FileAppend, %Time% %text%`n, %A_WorkingDir%\app.log
  294. }
  295.  
  296.  
  297. ;#----------------------------------------- Methods / functions above  -----------------------------------------
  298. ;Main code goes here !
  299. applog("")
  300. applog("")
  301. applog("")
  302. applog(" ----- App start ------")
  303. applog(" ----- some info ------")
  304. applog("AHK version =>" . A_AhkVersion)
  305. applog("OS Type     =>" . A_OSType)
  306. applog("OS Version  =>" . A_OSVersion)
  307. applog("is x64      =>" . A_Is64bitOS)
  308. applog("is elevated =>" . A_IsAdmin)
  309. applog(" ---- console log -----")
  310. IfExist, %A_WorkingDir%\keys.txt
  311. {
  312.     applog("found keys.txt")
  313.     Loop, read, %A_WorkingDir%\keys.txt
  314.     {
  315.         Loop, parse, A_LoopReadLine, %A_Tab%
  316.         {
  317.             steam_activate_key(A_LoopField)
  318.             Sleep,1000
  319.         }
  320.     }
  321.  
  322. }else{
  323.     ;add a keys.txt file plz
  324.     applog("we did not find any keys in keys.txt ! ")
  325.     MsgBox, 48, No keys.txt found !, Please add a keys.txt file in the root of this program.`n1 key per line.`nxxxx-xxxx-xxxx-xxxx
  326.     run notepad %A_WorkingDir%\keys.txt
  327. }
  328. applog("exiting app! bye bye !")
  329. applog(" ----- App End ------")
  330. ExitApp
  331. Escape::
  332. applog("pressed escape!")
  333. applog(" ----- App End ------")
  334. ExitApp
  335. Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement