Jump to content

Recommended Posts

Posted

Hi,

Im working my way through the tutorial fir AUTOIT.

 

I cant seem to get it to colse the notepad, the notepad just hangs there open.

 

here is the code.

run("Notepad.exe")
WinWaitActive("Untitled - Notepad")
send("This is some Text")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad","Do you want to save")
Send("!n")

 

 

Ive bet messing about with this for over an hour now, and something is worng.

 

Ive noticed , when notepad save, its saving as "*notpad" with a * on the front, this seems to be a problem, why is notepad prefixing with a *?

 

Posted
26 minutes ago, charlie2charlie said:

Ive noticed , when notepad save, its saving as "*notpad" with a * on the front, this seems to be a problem,

you've got it !. So you are not stuck ;) 

 

26 minutes ago, charlie2charlie said:

this seems to be a problem, why is notepad prefixing with a *?

No clue. Updates ?  :) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

Hi, you should see and learn about Send function in Help file, the help file has a good example for your what you want:
 

Example()

Func Example()
    ; Simulate the key combination Win + R to open the Run dialogue window.
    Send("#r")

    ; Wait 10 seconds for the Run dialogue window to appear.
    WinWait("Run", "", 10)

    ; Simulate entering notepad.exe and pressing the 'ENTER' key.
    Send("notepad.exe{Enter}")

    ; Wait 10 seconds for the Notepad window to appear.
    Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

    ; Simulate entering the following string and pressing the 'F5' key to input the date and time into edit control of Notepad.
    Send("Today's time/date is {F5}")

    ; Close the Notepad window using the handle returned by WinWait.
    WinClose($hWnd)

    ; Now a screen will pop up and ask to save the changes, the classname of the window is called
    ; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
    WinWaitActive("[CLASS:#32770]")
    Sleep(500)
    Send("{TAB}{ENTER}")
EndFunc   ;==>Example

 

Posted (edited)

The script below is the same as yours with 1 line added at the top.  By default, the title string has to be an exact match starting from the beginning of the window's title.  The asterisk (*) in the notepad title denotes that the file has been modified since it was last saved or created.  The OPT function that I added to the script says that the string you provide for the title can appear anywhere in the title.  If you use a -2, it will means it can appear anywhere in the title and is not case-sensitive.

Opt('WinTitleMatchMode', 2) ;1 = Start, 2 = SubString, 3 = Exact, 4 = Advanced, -1 to -4 = Case Insensitive.

run("Notepad.exe")
WinWaitActive("Untitled - Notepad")
send("This is some Text")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad","Save")
Send("!n")

 

*Updated example

Looks like there were a few changes to Notepad in Windows 10.  The Save dialog's visible text has changed.  The script above should work on Windows 10.  You can lookup each command in the Help file to see how and why it works.

Edited by TheXman
Posted

If you're wanting to use send or mouse clicks then recommend using Control.. functions (see ControlSend, ControlClick in the help file).  If you wanted to write text to a file, then would recommend using FileOpen, FileWrite functions.  Just my 2 cents.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...