Jump to content

Automate a java app (somewhat works)


Sigtran
 Share

Recommended Posts

Hi, I have a problem with the script below, maybe someone can point at my error there... (script is to automate my time spending scheduler, as im not always able to remember change it)

Everything seems to work fine, if I run its functionality separately, also everything seems to work, if I click on the java program once and leave it untouched.

I have turned the debug on and it get to the point where the clicks should happen in the while loop, but they don't happen at all times, tho they DO happen after a while, if I just click somewhere in that java program...

I tried moving the mouse first, but it doesn't seem to make any difference... not sure what else I can try here (at first I had if-elseif-elseif statements, but it made no difference).

Im new to autoit, so any help would be appreciated. thanks.

Opt("WinWaitDelay",100)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",1)
Opt("MouseClickDownDelay", 100)
Opt("TrayIconDebug", 1)
#include <Debug.au3>
_DebugSetup ( "Something goin on",False,1,"logging.txt" )
$previous   = Random(0,5,1)
$timeBreakOne   = "11:0" & $previous
$timeAfterBreakOne  = "11:"  & $previous + Random(10,15,1)
$timeLunch  = "13:"  & Random(25,35,1)
$timeAfterLunch  = "14:0" & Random(0,9,1)
$previous   = Random(0,5,1)
$timeBreakTwo   = "16:0" & $previous
$timeAfterBreakTwo  = "16:"  & $previous + Random(10,15,1)
$timeToFinish   = "18:00" ; might shutdown computer...
; Todays' Timetable
MsgBox(8192,"Todays' Timetable","Break one: " & $timeBreakOne & " - " & $timeAfterBreakOne & @LF & _
        "Lunch: " & $timeLunch & " - " & $timeAfterLunch & @LF & _
        "Break two: " & $timeBreakTwo & " - " & $timeAfterBreakTwo)
;Starting time is manual, in case I dont make it to work early enough...
; Avaialble
_WinWaitActivate("Some Java Program Here","")
MouseClick("left",504,13,1)
MouseClick("left",528,20,1)
While 1
$time = @hour & ":" & @MIN
;_DebugOut ("Got to While @ " & $time)
 
; First Break
_DebugOut ("Comparing 1 " & $time & " & " & $timeBreakOne)
If $time = $timeBreakOne Then
  ; reactivate winodw
  _DebugOut ("Break One True")
  _WinWaitActivate("Some Java Program Here","")
  MouseClick("left",501,13,1)
  MouseClick("left",528,69,1)
EndIf
 
; Avaialble
_DebugOut ("Comparing 1.1 " & $time & " & " & $timeAfterBreakOne)
If $time = $timeAfterBreakOne Then
  ; reactivate winodw
  _DebugOut ("Break One Finished True")
  _WinWaitActivate("Some Java Program Here","")
  MouseClick("left",504,10,1)
  MouseClick("left",518,13,1)
EndIf
 
; Lunch
_DebugOut ("Comparing 2 " & $time & " & " & $timeLunch)
If $time = $timeLunch Then
  ; reactivate winodw
  _DebugOut ("Lunch True")
  _WinWaitActivate("Some Java Program Here","")
  MouseClick("left",497,16,1)
  MouseClick("left",521,55,1)
EndIf
 
; Avaialble
_DebugOut ("Comparing 2.1 " & $time & " & " & $timeAfterLunch)
If $time = $timeAfterLunch Then
  ; reactivate winodw
  _DebugOut ("Lunch Finished True")
  _WinWaitActivate("Some Java Program Here","")
  MouseClick("left",501,17,1)
  MouseClick("left",514,30,1)
EndIf
; Second Break
_DebugOut ("Comparing 3 " & $time & " & " & $timeBreakTwo)
If $time = $timeBreakTwo Then
  ; reactivate winodw
  _DebugOut ("Break Two True")
  _WinWaitActivate("Some Java Program Here","")
  MouseClick("left",497,20,1)
  MouseClick("left",528,79,1)
EndIf
 
; Avaialble
_DebugOut ("Comparing 3.1 " & $time & " & " & $timeAfterBreakTwo)
If $time = $timeAfterBreakTwo Then
  ; reactivate winodw
  _DebugOut ("Break Two Finished True")
  _WinWaitActivate("Some Java Program Here","")
  MouseClick("left",497,17,1)
  MouseClick("left",518,31,1)
EndIf
 
;If $time = $timeToFinish Then
; Shutdown(1)
;EndIf
; Sleep 10 Seconds
Sleep(10000)
WEnd
Func _WinWaitActivate($title,$text,$timeout=0)
WinWait($title,$text,$timeout)
If Not WinActive($title,$text) Then WinActivate($title,$text)
WinWaitActive($title,$text,$timeout)
EndFunc
Edited by Sigtran
Link to comment
Share on other sites

ok, here is a debug, which showed that it just stalled before clicking and only came about doing something when I clicked:

Comparing 1 16:02 & 11:00

Comparing 1.1 16:02 & 11:14

Comparing 2 16:02 & 13:26

Comparing 2.1 16:02 & 14:06

Comparing 3 16:02 & 16:02

Break Two True

Comparing 3.1 16:02 & 16:15

Comparing 1 16:21 & 11:00

Comparing 1.1 16:21 & 11:14

Comparing 2 16:21 & 13:26

Comparing 2.1 16:21 & 14:06

Comparing 3 16:21 & 16:02

I also tried:

MouseMove (504,13,0)
  MouseDown("primary")
  Sleep(100)
  MouseUp("primary")

but it too stalls...

Edited by Sigtran
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...