Page 1 of 1

Intro. to AutoIT Automatically spawn window on secondary monitor

#1 Sn0wBum  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 178
  • Joined: 04-February 10

Posted 23 April 2010 - 04:31 AM

Tools Needed
AutoIT v3
Description

Quote

AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying "runtimes" required!

AutoIt was initially designed for PC "roll out" situations to reliably automate and configure thousands of PCs. Over time it has become a powerful language that supports complex expressions, user functions, loops and everything else that veteran scripters would expect.

Optional Tools
DisplayFusion
Description

Quote

DisplayFusion will make your dual monitor (or triple monitor or more) experience smooth and painless. With DisplayFusion you can add a taskbar to every monitor that works and looks just like the Windows Taskbar. Or take advantage of advanced multi-monitor wallpaper support, Flickr integration for image searching and fully customizable window management hotkeys. These are just a few of the many things that DisplayFusion can do.


This example will be working off of the basis that you have dual monitors, whether it be laptop+monitor or monitor+monitor, it should work regardless.

Now to the plot! Say you are at work or home and you have a program that opens and most likely will be drug to your secondary monitor. Enter AutoIt. AutoIt is a very useful tool for installation packages, window manipulation, and pretty much anything that would needs automated. First lets open up the SciTE Script Editor. Start > All Programs > AutoIt V3 > SciTE Script Editor (For those of you in XP).

The Editor has an IntelliSense like feature that will present you with all given functions of the letter you just typed.

;Comments begin with a semicolon



Back to the plot. That program that's moved to your extended desktop can be automated, so lets do so. Some of our work computers don't have a graphics cards that have hotkeys to send a window to the extended desktop, so we had to install DisplayFusion, so if your PC has hotkeys to complete this action, replace your methods with my notes to DisplayFusion.

First lets test the automated move...
AutoIT has functionality built in that can manipulate a window by its given title.
In this example we will open a dreamincode.net and move it to your secondary monitor.
;There is more than one way to open an external web page
;we will use the ShellExecute function
ShellExecute("http://www.dreamincode.net")



Now test this first snippet out by hitting F5.An IE window should spawn with DIC being the page.Pay attention to the title of your dreamincode window. We will add this next.

The next two functions work in combination to wait until your title parameter
is found and then the window is activated allowing the window to have access
to the keystrokes you will enter.

;There is more than one way to open an external web page
;we will use the ShellExecute function
ShellExecute("http://www.dreamincode.net")

;Remember that the title will be that of out last example
WinWait("Programming and Web Development Help | DreamInCode.net - Microsoft Internet Explorer")

;The same title is used here
WinActivate("Programming and Web Development Help | DreamInCode.net - Microsoft Internet Explorer")

;Now using the send command we will simulate raw key strokes
;Remember this part will be different if you are not user DisplayFusion
;If not, use what ever HotKeys your graphics card supports to send windows to
;your secondary monitor
Send("^#x")



Lets test it out! Hit F5 and sit back. If it worked, cool! If it didn't make sure your title is as it reads on your browser title.

The character "^#x" are special for AutoIT that stand for " Ctrl + WinKey + x". If you want to know some special keys like this check out AutoIT's documentation, it is well done.

Finally to make this run as best as possible.. we are going to add functionality to check if DisplayFusion is running , if it isn't we will start it .. and while all this is going down we will kill input so that nothing interrupts the key strokes.

;Checking if DisplayFusion is already running
if(ProcessExists("DisplayFusion.exe"))Then

Else
ShellExecute("C:\Program Files\DisplayFusion\DisplayFusion.exe")
EndIf

;Sleeping for 20 seconds to allow DisplayFusion to load
Sleep(20000)

;Opening Program or Website
ShellExecute("http://www.dreamincode.net")

;Block User Input *This can be exited by Ctrl+Alt+Delete*
BlockInput(1)

;Accessing Window and executing raw keystrokes
WinWait("Programming and Web Development Help | DreamInCode.net - Microsoft Internet Explorer")
WinActivate("Programming and Web Development Help | DreamInCode.net - Microsoft Internet Explorer")
Send("^#x")

:Enable User input
BlockInput(0)

;Exit AutoIT.Exe
Exit



If there is a problem when you test your scripts , there will most likely be an AutoIT icon on your taskbar, simply click on it scroll down and click exit to kill it.

Once you have your script work as you please go to the tools drop down, compile, and there you go! All done with the script! Now you can move the exe to your desktop or throw it in your startup programs and have it automatically run when you boot up.

Hope this was informative to everyone!

Is This A Good Question/Topic? 0
  • +

Replies To: Intro. to AutoIT

#2 Sn0wBum  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 178
  • Joined: 04-February 10

Posted 14 July 2010 - 10:24 AM

Excuse the typos... I was working a swing shift and it was about 1:30am when I was writing this... :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1