Skip to content

Instantly share code, notes, and snippets.

@x011
Last active March 12, 2017 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x011/4d12889d565516b0f69d1810b40bcb8d to your computer and use it in GitHub Desktop.
Save x011/4d12889d565516b0f69d1810b40bcb8d to your computer and use it in GitHub Desktop.
Prevents TWS (Interactive Brokers) Automatic Logout
#include <Debug.au3>
#include <date.au3>
Opt("MouseCoordMode", 0)
Opt("WinTitleMatchMode", 3)
While 1
If WinExists("[TITLE:####YOUR ACCOUNT ID HERE#### Exit Session Setting (Simulated Trading)]", "") Then
Local $hWnd = WinWait("[TITLE:####YOUR ACCOUNT ID HERE#### Exit Session Setting (Simulated Trading); CLASS:SunAwtFrame; INSTANCE:1]", "", 5)
Local $iState = WinGetState($hWnd)
if $iState == 15 Then
WinActivate($hWnd)
If StringInStr(_TimeHrMin(), "PM") Then
MouseClick($MOUSE_CLICK_LEFT, 215, 67, 2); PM
Sleep(1)
MouseClick($MOUSE_CLICK_LEFT, 184, 220, 2); click update
Sleep(1)
MouseClick($MOUSE_CLICK_LEFT, 246, 222, 2); click close
Else
MouseClick($MOUSE_CLICK_LEFT, 265, 68, 2) ; AM
Sleep(1)
MouseClick($MOUSE_CLICK_LEFT, 184, 220, 2) ; click update
Sleep(1)
MouseClick($MOUSE_CLICK_LEFT, 246, 222, 2) ; click close
EndIf
EndIf
Sleep(1)
EndIf
Sleep(5000)
WEnd
Func _TimeHrMin()
$hr = @HOUR
If $hr > 12 Then
$hr = $hr -12
$x = "PM"
Else
$x = "AM"
EndIf
$time = $x
Return ($time)
EndFunc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment