Jump to content

New User: Stuck on a Tutorial, Missing Something Obvious or Win7 X64 error?


Recommended Posts

I am embarrassed to ask for help at such an early juncture in my learning. But after reading all the manuals and searching the forum for, e.g. 'notepad,' 'win7 x64,' 'alt key,' 'using ! for alt,' etc., I haven't been able to come up with any one else who's had my problem.

The Stumbling Block: I was working through the very basic introductory scripts. On the notepad script, when I come to the line where I'm supposed to send alt-n to close the dialog box that pops up asking, roughly, 'Save before exiting?,' I can't get it to do anything.

My Detective Work: If I press 'alt-n' manually, at that point, it works, so I thought that maybe the send("!n") command might not be working properly for me. I also thought it might be a problem with recognizing the dialog box. I tried to find another program that had a dialog box-- hopefully not requiring an alt-key combination-- but all of them seem to require alt-keys. So I'm left uncertain whether it's the alt-key signal (exclamation mark) or the dialog box, or something else I haven't considered.

Has anything similar happened to anyone else? I tried many forum searches, and even ended up reading most of a book on scripting, looking for anything that might help (and learning much in the process) but couldn't find an analogous problem. Am I too stupid to learn to code? I feel very bad getting hung up on the second tutorial. Apologies if I am wasting people's time.

; Script Start - Add your code below here
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This is some text.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad", "Do you want to save")
Send("!n")

(edited to add the autoit command: thanks m23)

Edited by EnderWiggin
Link to comment
Share on other sites

You could use

ControlClick ( "Untitled - Notepad", "", 7)

The controlid (7) was determined by AutoIt Window Info on a german Notepad.

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

what happens if you

Send("{ALT}n")

instead?

Thank you, water and kaotkbliss, for responding so quickly. I tried both of your ideas and run into the same problem as before. The script runs. It opens notepad, types the phrase, and tries to exit, but won't send the alt-n to the dialog box, so it ends with the last window, 'save changes?' still open.

I used the window info tool to get a summary of the dialog box, thinking I might have a different number for the control than water, since he stipulated that it was a german version. I copied that here at the end of this post. Not sure if it makes sense. I was looking for a control number similar to 7. I assume that's not the class #32770?

I also noticed I couldn't type "{Alt}" and can't type it here either. The squiggly brackets won't appear. Though I can type it in word and copy/paste. I've had the strange experience with my keyboard that if I hit the forward bracket button it outputs -[. So I type "[" and get "-["

Could I have some kind of keyboard issue that in turn is affecting what autoit gets when it tries to send keyboard commands? Or wouldn't the keyboard itself enter into autoit's simulation of a keystroke, specifically alt-n?

Sorry for the repeated and undoubtedly mundane queries. I very much appreciate the attempts to help thus far.

>>>> Window <<<<

Title: Notepad

Class: #32770

Position: 776, 487

Size: 366, 140

Style: 0x96C80284

ExStyle: 0x00010101

Handle: 0x00000000000702CE

>>>> Control <<<<

Class: DirectUIHWND

Instance: 1

ClassnameNN: DirectUIHWND1

Name:

Advanced (Class): [CLASS:DirectUIHWND; INSTANCE:1]

ID:

Text:

Position: 0, 0

Size: 350, 102

ControlClick Coords: 122, 2

Style: 0x56000000

ExStyle: 0x00000000

Handle: 0x00000000000A02EC

>>>> Mouse <<<<

Position: 906, 519

Cursor ID: 2

Color: 0xFFFFFF

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<

&Save

Do&n't Save

Cancel

>>>> Hidden Text <<<<

Link to comment
Share on other sites

Found the problem:

The window appearing after WinClose has a different title. So your script now waits forever.

Change WinWaitActive to "WinWaitActive("Editor", ...)" and everything should run fine.

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

Found the problem:

The window appearing after WinClose has a different title. So your script now waits forever.

Change WinWaitActive to "WinWaitActive("Editor", ...)" and everything should run fine.

Hooray! You were right, it was a change in the name of the window, from "Untitled - Notepad" to "Notepad" that was causing the hangup. I changed the code to:

; Script Start - Add your code below here
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This is some text.")
WinClose("Untitled - Notepad")
WinWaitActive("Notepad")
Send("!n")

And it worked. What a great feeling. Thank you so much.

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