Jump to content

Set focus


Recommended Posts

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!

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

Link to comment
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.
Link to comment
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

Link to comment
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]

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

Link to comment
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. >_<

Link to comment
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]

Link to comment
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]

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