Jump to content

Select menuitem from other app


cheeth
 Share

Recommended Posts

WinMenuSelectItem

Thanks SmOke. I used "WinMenuSelectItem" but i did not work. Here is my code:

#include <GUIConstants.au3>

$title = "Untitled - Notepad"

Run("notepad.exe")

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

WinWaitActive($title )

; Now that the Notepad window is active type some text

Send("Hello from Notepad.{ENTER}1 2 3 4 5 6 7 8 9 10{ENTER}")

$blnSuccess = WinMenuSelectItem($title , "", "File", "Save As..." )

If ($blnSuccess = 1) then

MsgBox("Success", "", "Select menu item successful")

Else

MsgBox("Fail", "", "Select menu item fail")

EndIf

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Wend

Link to comment
Share on other sites

  • Moderators

If you want to save something to a text file, you could do it with FileWrite fairly easy:

Example:

$FILE = FileGetShortName(@HomeDrive & '\SaveTextTest.txt')
FileWrite($FILE, 'Just an example')
Run(@Comspec & ' /c start ' & $FILE, '', @SW_HIDE)
MsgBox(64, 'Info:', 'File is saved here: ' & FileGetLongName($FILE))

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

If you want to save something to a text file, you could do it with FileWrite fairly easy:

Example:

$FILE = FileGetShortName(@HomeDrive & '\SaveTextTest.txt')
FileWrite($FILE, 'Just an example')
Run(@Comspec & ' /c start ' & $FILE, '', @SW_HIDE)
MsgBox(64, 'Info:', 'File is saved here: ' & FileGetLongName($FILE))

Thanks SmOke. I want to select a menu item on other app from AutoScript. Saving text from NotePad is just a example. Btw, Thank for your help

Link to comment
Share on other sites

  • Moderators

Hmm, I don't know what to tell you, it's a lot of trial and error.

Try this:

$Window = 'Untitled - Notepad'
If Not WinExists($Window) Then Run('notepad.exe')
WinWaitActive($Window)

Sleep(1000)

If WinMenuSelectItem($Window, '', '&File', 'Save &As...') Then
    MsgBox(64, 'Info', 'Success, Save As is open')
Else
    MsgBox(64, 'Info', 'Failure')
EndIf

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hmm, I don't know what to tell you, it's a lot of trial and error.

Try this:

$Window = 'Untitled - Notepad'
If Not WinExists($Window) Then Run('notepad.exe')
WinWaitActive($Window)

Sleep(1000)

If WinMenuSelectItem($Window, '', '&File', 'Save &As...') Then
    MsgBox(64, 'Info', 'Success, Save As is open')
Else
    MsgBox(64, 'Info', 'Failure')
EndIf

Now it works. Thanks SmOke. Another question, How do you know text of menu ('&File', 'Save &As...'). I did not see any underscore below "F" and "A" char. I used AutoIt Window Info, but got nothing.

Link to comment
Share on other sites

  • Moderators

As I said above, it was trial and error for me.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Now it works. Thanks SmOke. Another question, How do you know text of menu ('&File', 'Save &As...'). I did not see any underscore below "F" and "A" char. I used AutoIt Window Info, but got nothing.

Just pressing the Alt key should make the underlines appear under the accellerator keys in the menu.

:whistle:

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