[연습]사내 온라인 산업안전교육 자동수강 및 자동시험응시기
#AutoIt3Wrapper_icon=AutoㅇㅇㅇㅇLecture.ico
; 목적 : AutoIt 학습 및 imagesearch 라이브러리 사용법 학습
; 버전 : 3.3.8.1
; 일자 : 2013.06월의 어느날
; 동작 :
; ㅇㅇㅇㅇ 사내 산업안전교육 온라인 교육 및 시험을 자동으로 수강 및 응시한다.
#include <ImageSearch.au3>
Global $gs_mainwintitle = "ㅇㅇㅇㅇ㈜"
Global $gs_lecwintitle = "교안보기..."
Global $gs_googledef = "Google 계정"
Global $gs_chromedef = "- Chrome"
Global $ghWnd_MWin = 0
Global $gs_userid = ""
Global $gs_userpw = ""
Global $gl_maxleccnt = 5
Global $gl_limitsec = 1210
Global $gpos_basex1 = 0
Global $gpos_basey1 = 0
Global $Paused
Global $gl_tolerance = 0
If MutexExists("ㅇㅇㅇㅇOnlineLecture") Then
MsgBox(0, "알림", "자동수강이 이미 실행 중입니다.")
ToolTip("")
Exit
EndIf
Func MutexExists($sOccurenceName)
Local $ERROR_ALREADY_EXISTS = 183, $handle, $lastError
$sOccurenceName = StringReplace($sOccurenceName, "", "")
$handle = DllCall("kernel32.dll", "int", "CreateMutex", "int", 0, "long", 1, "str", $sOccurenceName)
$lastError = DllCall("kernel32.dll", "int", "GetLastError")
Return $lastError[0] = $ERROR_ALREADY_EXISTS
EndFunc
HotKeySet("{ESC}", "ExitForce")
HotKeySet("+!p", "TogglePause")
ToolTip("산업안전 자동수강 실행중...", 0, 0)
If FileExists(@ProgramFilesDir & "\Google\Chrome\Application\chrome.exe") Then
If MsgBox(4,"알림", "ㅇㅇㅇㅇ 온라인 법정안전교육 자동수강을 시작하시겠습니까?" & @CRLF & _
"(모든 강의를 수강하신 후 이 프로그램을 재실행 하시면" & @CRLF & " 자동 시험응시가 가능합니다!!)") == 6 Then
While 1
$gl_tolerance = InputBox("입력", "이미지 검색 오차범위를 설정하여 주세요.(1~10사이숫자범위)" & @CRLF & @CRLF & "검색 오차범위는 프로그램이 창을 찾지 못하면 높게 잡아주세요!!" & @CRLF & @CRLF &"오차범위가 낮을수록 프로그램 정확도가 올라갑니다!!" & @CRLF & "(3정도가 가장 좋은 인식율을 보이는것 같습니다)",3,"",400,250)
If $gl_tolerance == "" Then
If MsgBox(4, "입력", "프로그램을 실행을 중지하시겠습니까?") == 6 Then
ToolTip("")
Exit
EndIf
EndIf
If $gl_tolerance < 1 or $gl_tolerance > 10 Then
MsgBox(0, "알림", "1~10 사이 숫자만 입력가능합니다!!")
Else
ExitLoop
EndIf
WEnd
Main()
Else
MsgBox(0, "알림", "사용자 요청으로 자동수강을 종료합니다!!", 3)
ToolTip("")
Exit
EndIf
Else
If MsgBox(4, "알림", "크롬 브라우저가 설지되어 있지 않습니다!!" & @CRLF & "자동수강은 크롬 브라우저가 설치되어 있어야 정상 동작합니다!!" & @CRLF & "크롬 브라우저를 설치하시겠습니까?") == 6 Then
$ll_retval = ShellExecute("explorer.exe", "http://www.google.com/intl/ko/chrome/browser/")
If $ll_retval == 1 Then
MsgBox(0, "알림", "멋진 선택이십니다. 크롬 설치후 다시한번 실행하여 주세요!!")
ToolTip("")
Exit
Else
MsgBox(0, "알림", "알수없는 오류로 인하여 크롬브라우저 설치 진행에 실패하였습니다!! 아쉽지만 다음기회에....")
ToolTip("")
Exit
EndIf
Else
MsgBox(0, "알림", "크롬브라우저가 없어 진행을 종료합니다!!")
ToolTip("")
Exit
EndIf
EndIf
Func Main()
$lpos_x1 = 0
$lpos_y1 = 0
$ll_retval = 0
While ProcessExists("chrome.exe")
ProcessClose("chrome.exe")
WEnd
Close_ExistWindow($gs_mainwintitle)
Close_ExistWindow($gs_lecwintitle)
$ghWnd_MWin = Find_Window($gs_mainwintitle)
If $ghWnd_MWin < 0 Then
MsgBox(0, "알림", "ㅇㅇㅇㅇ 온라인 법정안전교육 창을 찾지 못했습니다!!")
ToolTip("")
Exit
EndIf
$ll_retval = WinMove($ghWnd_MWin,"", 0,0,1024,768)
If $ll_retval == 0 Then
MsgBox(0, "알림", "ㅇㅇㅇㅇ 온라인 법정안전교육 창을 찾지 못했습니다!!")
ToolTip("")
Exit
EndIf
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("GoogleDef.bmp",3,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval == 1 Then
Activate_MainWin($ghWnd_MWin)
MouseMove($lpos_x1+85,$lpos_y1)
Sleep(100)
MouseClick("left")
EndIf
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("ChromeDef.bmp",3,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval == 1 Then
Activate_MainWin($ghWnd_MWin)
MouseMove($lpos_x1,$lpos_y1)
Sleep(100)
MouseClick("left")
EndIf
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("LectureDef.bmp",3,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval == 1 Then
Activate_MainWin($ghWnd_MWin)
MouseMove($lpos_x1,$lpos_y1)
Sleep(100)
MouseClick("left")
EndIf
Activate_MainWin($ghWnd_MWin)
Input_UserInfo()
Login_Site()
GoToLectureRoom()
WatchLecture()
EndFunc
Func GetBasePosition()
$lpos_x1 = 0
$lpos_y1 = 0
$lpos = 0
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("BasePosition.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval <> 1 Then
MsgBox(0,"알림", "시험답안지 기준점을 찾는데 실패하였습니다" & @CRLF & "프로그램을 종료합니다!!")
ToolTip("")
Exit
EndIf
MouseMove($lpos_x1, $lpos_y1)
$lpos = MouseGetPos()
$gpos_basex1 = $lpos[0] + 1
$gpos_basey1 = $lpos[1] + 3
;MsgBox(0, "알림", "Mouse x,y:" & $pos[0] & "," & $pos[1])
EndFunc
Func AnswerSheetMatrix($al_ques_no, $al_answ_no, ByRef $apos_x1, ByRef $apos_y1)
$lpos_x1 = $gpos_basex1
If $al_ques_no <= 6 Then
$lpos_y1 = $gpos_basey1
Else
$al_ques_no = $al_ques_no - 7
$lpos_y1 = $gpos_basey1 + 316
EndIf
$apos_x1 = $lpos_x1 + (41 * $al_answ_no)
$apos_y1 = $lpos_y1 + (57 * $al_ques_no)
EndFunc
Func EnterExam()
Dim $larray_answer[11] = [0,4,4,4,2,1,4,2,3,4,3]
$lpos_x1 = 0
$lpos_y1 = 0
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("ExamSeason.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval <> 1 Then
MsgBox(0,"알림", "3분기 근로자 정기교육만 자동응시 가능합니다!!" & @CRLF & "프로그램을 종료합니다!!")
ToolTip("")
Exit
EndIf
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("EnterExam01.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval <> 1 Then
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("EnterExam02.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
EndIf
If $ll_retval <> 1 Then
MsgBox(0,"알림", "응시할 시험이 없습니다!!" & @CRLF & "프로그램을 종료합니다!!")
ToolTip("")
Exit
EndIf
Activate_MainWin($ghWnd_MWin)
MouseMove($lpos_x1,$lpos_y1)
Sleep(1000)
MouseClick("left")
Sleep(1000)
MouseMove(0,0)
For $i = 1 To 6
Send("{RIGHT}")
Sleep(50)
Next
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("AnswerSheet.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval <> 1 Then
MsgBox(0,"알림", "답안지를 찾을 수 없습니다!!" & @CRLF & "프로그램을 종료합니다!!")
ToolTip("")
Exit
EndIf
GetBasePosition()
Activate_MainWin($ghWnd_MWin)
MouseMove($lpos_x1,$lpos_y1)
Sleep(100)
MouseClick("left")
$lpos_basex1 = $lpos_x1
$lpos_basey1 = $lpos_y1
For $i = 1 To UBound($larray_answer) - 1
If $i == 8 Then
Activate_MainWin($ghWnd_MWin)
MouseMove($lpos_basex1,$lpos_basey1)
Sleep(50)
MouseClick("left")
For $j = 1 To 3
Activate_MainWin($ghWnd_MWin)
Send("{DOWN}")
Sleep(50)
Next
EndIf
AnswerSheetMatrix($i - 1, $larray_answer[$i] - 1, $lpos_x1, $lpos_y1)
Activate_MainWin($ghWnd_MWin)
MouseMove($lpos_x1,$lpos_y1)
Sleep(100)
MouseClick("left")
Sleep(100)
Next
Activate_MainWin($ghWnd_MWin)
MouseMove($lpos_basex1,$lpos_basey1)
Sleep(50)
MouseClick("left")
For $j = 1 To 3
Activate_MainWin($ghWnd_MWin)
Send("{DOWN}")
Sleep(50)
Next
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("Submit.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval <> 1 Then
MsgBox(0,"알림", "제출버튼을 찾을 수 없습니다!!" & @CRLF & "수동으로 제출해주세요!!")
EndIf
Activate_MainWin($ghWnd_MWin)
MouseMove($lpos_x1,$lpos_y1)
Sleep(100)
MouseClick("left")
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("Confirm.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval <> 1 Then
MsgBox(0,"알림", "제출버튼을 찾을 수 없습니다!!" & @CRLF & "수동으로 제출해주세요!!")
EndIf
Activate_MainWin($ghWnd_MWin)
MouseMove($lpos_x1,$lpos_y1)
Sleep(100)
MouseClick("left")
MsgBox(0, "알림", "시험 응시가 끝났습니다!! 쌍콤한 하루 되세요~")
ToolTip("")
Exit
EndFunc
Func WatchLecture()
$lpos_x1 = 0
$lpos_y1 = 0
$ll_errcnt = 0
$idx_lec = 1
While 1
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("Completing.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval <> 1 Then
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("NotComplete.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
EndIf
If $ll_retval == 1 Then
$lpos_x1 = $lpos_x1 - 330
Activate_MainWin($ghWnd_MWin)
MouseMove($lpos_x1,$lpos_y1)
Sleep(1000)
MouseClick("left")
Sleep(2000)
MouseMove(0,0)
$ll_retval = WinSetState($ghWnd_MWin, "", @SW_MINIMIZE)
$ll_retval = WinExists($gs_lecwintitle)
If $ll_retval == 1 Then
$lhWnd_LecWin = WinGetHandle($gs_lecwintitle)
$ll_retval = WinMove($lhWnd_LecWin,"", 0,0,1024,768)
$ll_retval = WinSetState($lhWnd_LecWin, "", @SW_MINIMIZE)
$ls_msg = ""
ProgressOn("자동수강 진행사항", String($idx_lec) & "차시 강의 " & "0% 수강중...(다른작업 가능합니다.)", "")
$ll_watchrate = 0
; 테스트 30초 수강!!
;$gl_limitsec = 10
For $ll_remainsec = 1 To $gl_limitsec
$ll_watchrate = Round(($ll_remainsec / $gl_limitsec) * 100, 0)
$ls_msg = "중지:ESC / 일시정지:Alt+Shift+p"
$ll_retval = WinExists($lhWnd_LecWin)
If $ll_retval <> 1 Then
ProgressOff()
MsgBox(0, "알림", "강의창이 사라져 자동수강을 종료합니다!!")
ToolTip("")
Exit
EndIf
ProgressSet($ll_watchrate, String($ll_watchrate) & "% 수강중...(다른작업 가능합니다.)", $ls_msg)
Sleep(1000)
Next
ProgressSet(100, "강의 100% 수강완료!!", $ls_msg)
Sleep(500)
ProgressOff()
WinClose($lhWnd_LecWin)
$idx_lec = $idx_lec + 1
If $idx_lec > $gl_maxleccnt Then
ExitLoop
EndIf
Else
MsgBox(0,"알림","미수강 강의 리스트를 찾지 못하였습니다!!" & @CRLF & "3초후 강의를 재탐색 합니다!!", 3)
WinClose($gs_lecwintitle)
$ll_errcnt = $ll_errcnt + 1
If $ll_errcnt >= 3 Then
MsgBox(0, "알림", "더이상 수강 가능한 강의를 찾을 수 없어 프로그램을 종료 합니다!!")
ToolTip("")
Exit
EndIf
EndIf
Else
MsgBox(0,"알림","미수강 강의 리스트를 찾지 못하였습니다!!" & @CRLF & "3초후 강의를 재탐색 합니다!!", 3)
WinClose($gs_lecwintitle)
$ll_errcnt = $ll_errcnt + 1
If $ll_errcnt >= 3 Then
MsgBox(0, "알림", "더이상 수강 가능한 강의를 찾을 수 없어 프로그램을 종료 합니다!!")
ToolTip("")
Exit
EndIf
EndIf
WEnd
EndFunc
Func GoToLectureRoom()
$lpos_x1 = 0
$lpos_y1 = 0
Activate_MainWin($ghWnd_MWin)
For $i = 1 To 3
If $i == 3 Then
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("PossibleExam01.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval == 1 Then
If MsgBox(4, "알림", "이미 모든 강의를 수강하셨습니다!! 시험에 응시 하시겠습니까?") == 6 Then
EnterExam()
ToolTip("")
Exit
EndIf
EndIf
EndIf
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("ClassRoom0" & String($i) & ".bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval == 1 Then
Activate_MainWin($ghWnd_MWin)
MouseMove($lpos_x1,$lpos_y1)
Sleep(1000)
MouseClick("left")
Sleep(1000)
Else
MsgBox(0,"알림","강의실 바로가기를 찾지 못하였습니다!!")
ToolTip("")
Exit
EndIf
Next
EndFunc
Func Activate_MainWin($ahWnd_Win)
$ll_retval = WinActivate($ahWnd_Win)
MouseMove(0,0)
If $ll_retval == 0 Then
MsgBox(0, "알림", "ㅇㅇㅇㅇ 온라인 법정안전교육 창을 찾지 못했습니다!!")
ToolTip("")
Exit
EndIf
EndFunc
Func Login_Site()
$lpos_x1 = 0
$lpos_y1 = 0
Activate_MainWin($ghWnd_MWin)
$ll_retval = _WaitForImageSearch("Logout.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
if $ll_retval == 1 Then
MouseMove($lpos_x1-55,$lpos_y1+19)
Sleep(1000)
MouseClick("left")
Sleep(3000)
EndIf
$lpos_x1 = 0
$lpos_y1 = 0
$ll_retval = _WaitForImageSearch("Login.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval == 1 Then
Activate_MainWin($ghWnd_MWin)
MouseMove($lpos_x1,$lpos_y1-12,1)
MouseClick("left")
Send($gs_userid)
Sleep(500)
Send("{Enter}")
Sleep(500)
Send("{Tab}")
Sleep(500)
Send($gs_userpw)
Send("{Enter}")
$ll_retval = _WaitForImageSearch("Loginfail.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
If $ll_retval == 1 Then
Close_ExistWindow($gs_mainwintitle)
MsgBox(0, "알림", "입력하신 ID 또는 PW가 올바르지 않습니다!!" & @CRLF & "확인 후 다시 시도하여 주세요!!")
ToolTip("")
Exit
EndIf
Else
MsgBox(0,"알림","로그인창을 찾지 못하였습니다!!")
ToolTip("")
Exit
EndIf
EndFunc
Func Input_UserInfo()
$gs_userid = ""
$gs_userpw = ""
$gs_userid = InputBox("입력", "교육대상자 ID를 입력!!" & @CRLF & "(그룹웨어ID[사번아님]})")
$gs_userpw = InputBox("입력", "교육대상자 비밀번호 입력!!" & @CRLF & "(기본패스워드 1111)", "", "*")
If $gs_userid == "" Or $gs_userpw == "" Then
If MsgBox(4, "알림", "교육대상자 ID 또는 패스워드가 올바르지 않습니다!!" & @CRLF & "다시 입력하시겠습니까?") == 6 Then
Input_UserInfo()
Else
MsgBox(0, "알림", "프로그램을 종료합니다!!",5)
ToolTip("")
Exit
EndIf
Else
Return 1
EndIf
EndFunc
Func Find_Window($as_wintitle)
$ll_retval = 0
$ll_retval = WinExists($as_wintitle)
If $ll_retval == 1 Then
Return WinGetHandle($as_wintitle)
Else
$ll_retval = ShellExecute("chrome.exe", "--incognito http://ㅇㅇㅇㅇ.산업안전보건교육.kr/")
If $ll_retval == 1 Then
Sleep(2000)
Return WinGetHandle($as_wintitle)
Else
Return -1
EndIf
EndIf
EndFunc
Func Close_ExistWindow($as_wintitle)
While 1
$lhWnd_temp = 0
$ll_retval = 0
$lpos_x1 = 0
$lpos_y1 = 0
$ll_retval = WinExists($as_wintitle)
If $ll_retval == 1 Then
$lhWnd_temp = WinGetHandle($as_wintitle)
Activate_MainWin($lhWnd_temp)
Sleep(500)
$ll_retval = WinMove($lhWnd_temp,"", 0,0,1024,768)
If $ll_retval == 0 Then
MsgBox(0, "알림", "ㅇㅇㅇㅇ 온라인 법정안전교육 창을 찾지 못했습니다!!")
ToolTip("")
Exit
EndIf
$ll_retval = _WaitForImageSearch("Logout.bmp",5,1,$lpos_x1,$lpos_y1,$gl_tolerance)
if $ll_retval == 1 Then
MouseMove($lpos_x1-55,$lpos_y1+19)
Sleep(500)
MouseClick("left")
Sleep(1000)
EndIf
WinClose($lhWnd_temp)
Else
ExitLoop
EndIf
WEnd
EndFunc
Func ExitForce()
If MsgBox(4,"알림", "ㅇㅇㅇㅇ 온라인 법정안전교육 자동수강을 강제 종료 하시겠습니까?") == 6 Then
ToolTip("")
Exit
EndIf
EndFunc
Func TogglePause()
$Paused = Not $Paused
While $Paused
Sleep(100)
ToolTip("자동수강 일시정지중...", -1, -1)
WEnd
ToolTip("자동수강 진행중....", -1, -1)
EndFunc