Jump to content

Setting Active Window


LiMuBai
 Share

Recommended Posts

$size = WinGetClientSize("[active]")
MsgBox(0, "Active window's client size is (width,height):", $size[0] & " " & $size[1])

An small example from the help file about '[active]'

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Uhm, could someone tell me whats the script to choose the application?

For example

I open Notepad A and Notepad B.

I want AutoIt to work only on Notepad A but they have the same name("Notepad"), what should I do?

This is one way.

Run("notepad.exe")
WinWaitActive("[CLASS:Notepad]", "")
$hTitle = WinGetTitle("") ; First window title

Run("notepad.exe")
WinWaitActive("[CLASS:Notepad]", "")
$hTitle1 = WinGetTitle("") ; Second window title

;Temporarily add character to title to differentiate Windows
WinSetTitle($hTitle1, "", "B" & $hTitle1)
$hTitle1 = WinGetTitle("") ; Second window title modified


WinActivate($hTitle1, "")
ControlSend($hTitle1, "", ControlGetFocus(WinGetTitle('')), "Second Window") ; Send to second window

Sleep(2000)

WinActivate($hTitle, "")
ControlSend($hTitle, "", ControlGetFocus(WinGetTitle('')), "First Window") ; Send to first window

Sleep(1000)

; Remove added character from title on completion
WinActivate($hTitle1, "")
WinSetTitle($hTitle1, "", StringTrimLeft($hTitle1, 1)) ; Second window title as at start
Link to comment
Share on other sites

Your code will work just if LiMuBai open the Notepads with an AutoIt code. What about if the Notepads are opened by hands (when user is opened them with mouse clicking)?

Along a similar theme, try this.

;Open two Notepad Windows by hands ( mouse clicking). Then run this.

WinWaitActive("[CLASS:Notepad]", "")
$hTitle1 = WinGetTitle("") ; AutoIt Controlled Notepad

;Temporarily add character to title to differentiate Notepad Windows
WinSetTitle($hTitle1, "", "B" & $hTitle1)
$hTitle1 = WinGetTitle("") ; AutoIt Controlled Notepad window title modified


WinActivate($hTitle1, "")
ControlSend($hTitle1, "", ControlGetFocus(WinGetTitle('')), "AutoIt Controlled Window") ; Send to AutoIt Controlled Notepad window

MsgBox(0,"","The AutoIt Controlled Notepad starts with the letter B")

; Remove added character from title on completion
WinActivate($hTitle1, "")
WinSetTitle($hTitle1, "", StringTrimLeft($hTitle1, 1)) ; AutoIt Controlled Notepad window title as at start
Link to comment
Share on other sites

The notepads were just an example o.o

Here's the script I have..its for a game

WinActivate("Pirate King Online - Caribbean Chapters 1.35.00001", "")

While 1

ControlSend("Pirate King Online - Caribbean Chapters 1.35.00001", "", "", "{F5}")

Sleep(1000)

ControlSend("Pirate King Online - Caribbean Chapters 1.35.00001", "", "", "{INS}")

Sleep(5000)

Wend

With that, all clients of "Pirate King Online - Caribbean Chapters 1.35.00001" will use the script and I want only one specific client to use the script. That way, while one client uses the script, I could use another client w/o the script being played in it.

Thanks for help so far.

Link to comment
Share on other sites

You could start it once, get the handle, start the second one. Now you have the handle from of 1 of them so u can ControlSend to one with handle and to one without hanlde.

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

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...