inmysights

Set focus

17 posts in this topic

Hello,

I am new to autoit and think it is a great tool!

I have read some of the tutorials and understand the basics to get going now. I have one question which seems rather simple to do but I think I am missing something. can you please explain if I understand this wrong:

; Run Notepad

Run("notepad.exe")

; Wait for the Notepad become active - it is titled "Untitled - Notepad" on English systems

WinWaitActive("Untitled - Notepad")

Does WinWaitActive set the focus for the script to run on that instance of that notepad?

that is how I am reading that.

I tried to make my own script with this, and it just runs on my desktop, it wont set focus to the screen I have open, how do you set autoit to run a script on a open window?

Thank you!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

welcome to the forum.

Here you'll find a good example that takes data from a GUI and inserts it into Notepad. It shows how to wait for a window and set focus to it.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

RunWait("notepad.exe") ;Will run notepad and pause the script until the window exists
WinActivate("Untitled - Notepad") ;Will activate the window
Send("Hey! I just used the Send function!")

Share this post


Link to post
Share on other sites

Thank you, got it to set focus to the window, WinActivate did the trick!

Why does this not work?

WinActivate("Untitled - Notepad")

MouseClickDrag("left", 500, 700, 500, 300)

Instead of dragging inside my instance of notepad, it defaults to my windows desktop and drags there? How to I get it to stay in notepad and drag?

thank you

Share this post


Link to post
Share on other sites

Function AutoItSetOption

Use

2 = relative coords to the client area of the active window


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

that worked, than you for your help!!!!!!

Share this post


Link to post
Share on other sites

RunWait("notepad.exe") ;Will run notepad and pause the script until the window exists
WinActivate("Untitled - Notepad") ;Will activate the window
Send("Hey! I just used the Send function!")

Perhaps you should have tried that Info. >_<

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Perhaps you should have tried that Info. :(

What do you mean? >_<

Share this post


Link to post
Share on other sites

is this proper logic:

AutoItSetOption ( "PixelCoordMode" , 2 )

$var = PixelGetColor( 10 , 100 )

If $var <> $var Then

MouseClick("left")

EndIf

What I want to do is, if the pixel color stored in var changes to any other color that what I stored there on the active window, then it will left click for me.

Thank you

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Ah.

Runs an external program and pauses script execution until the program finishes.

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
WinActivate("Untitled - Notepad")
Send("Hey! I just used the Send function!")

>_<

Edited by Info

Share this post


Link to post
Share on other sites

Ah.

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
WinActivate("Untitled - Notepad")
Send("Hey! I just used the Send function!")

>_<

Did you actually run the code?

Runwait was not your only error.

And now you have added a WinWaitActive before a WinActivate???

You will need to use the "raw" parm for Send...

When it is simple code like this - just run it before posting.

{I'm not picking on ya - just pointing out a good practice.}


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

I am still trying to get this to work, is it correct? logic seems right, but it does not work.

AutoItSetOption ( "PixelCoordMode" , 2 )

$var = PixelGetColor( 10 , 100 )

If $var <> $var Then

MouseClick("left")

EndIf

What I want to do is, if the pixel color stored in var changes to any other color that what I stored there on the active window, then it will left click for me.

Thank you

Share this post


Link to post
Share on other sites

Did you actually run the code?

Runwait was not your only error.

And now you have added a WinWaitActive before a WinActivate???

You will need to use the "raw" parm for Send...

When it is simple code like this - just run it before posting.

{I'm not picking on ya - just pointing out a good practice.}

Actually I did test it at the first time, it didn't work but I thought it's fine because my notepad language is Hebrew.

Not only that, the OP said my script helped him. >_<

Share this post


Link to post
Share on other sites

... if the pixel color stored in var changes to any other color that what I stored there on the active window, then it will left click for me. ...

AutoItSetOption("PixelCoordMode", 2)

;get color info the first time
$var = PixelGetColor(10, 100)

Do
    Sleep(99)
Until $var <> PixelGetColor(10, 100) ;watch for change

MouseClick("left")

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Actually I did test it at the first time, it didn't work but I thought it's fine because my notepad language is Hebrew.

Not only that, the OP said my script helped him. >_<

Okay, just avoid special characters like "!" in a send line or add the raw parm

Send("Hey! I just used the Send function!", 1)

'!'

This tells AutoIt to send an ALT keystroke, therefore Send("This is text!a") would send the keys "This is text" and then press "ALT+a".


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
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