Skip to content

Instantly share code, notes, and snippets.

@TLMcode
Created April 1, 2016 11:18
Show Gist options
  • Save TLMcode/a42ea458a3ac6fa7f2a9ea0e241dbd53 to your computer and use it in GitHub Desktop.
Save TLMcode/a42ea458a3ac6fa7f2a9ea0e241dbd53 to your computer and use it in GitHub Desktop.
RunChrome() waits for page to load then moves the chrome window to the coordinate array.
new RunChrome( "https://autohotkey.com", [ 0, 0, 1000, 500 ] )
return
Esc::ExitApp
class RunChrome
{
__New( url, coords )
{
this.arr := this.EnumWindows(), this.ShellHookWindow( 1 )
this.coords := coords
Run % "chrome.exe -new-window " url
return this
}
EnumWindows()
{
return ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process WHERE name = 'chrome.exe'")
}
ShellHookWindow( typ )
{
static msgNum
Gui +LastFound
DllCall( ( typ = 0 ? "Der" : "R" ) "egisterShellHookWindow", UInt, WinExist() )
OnMessage( typ != 0 ? (msgNum := DllCall( "RegisterWindowMessage", Str, "SHELLHOOK" ) ) : msgNum, (typ = 1 ) ? this.ShellEventHandler.Bind( this ) : )
}
ShellEventHandler( msg, wP )
{
WinGet, wProc, ProcessName, % "ahk_id " wP
if ( wProc = "chrome.exe" )
pidArr := this.EnumWindows()
WinGetTitle, wTitle, % "ahk_id " wP
if ( pidArr.count() > this.arr.count() && !InStr( wTitle, "Legacy" ) )
{
WinMove, % "ahk_id " wP,, % this.coords.1, % this.coords.2, % this.coords.3, % this.coords.4
this.ShellHookWindow( 0 )
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment