Jump to content

How to click Menu Items without using x,y co-ordinates?


Mayur
 Share

Recommended Posts

Hi All,

I am trying to automate Window based application using AutoIt.

For Clicking Menu Items right now I am using MouseClick methods but i observed that its behaviour is different on different machines & different OS so for overcoming this problem can any one have solution to click Menu Items without x,y co-ordinates.

Thanks,

Mayur

Link to comment
Share on other sites

  • Moderators

Mayur,

Welcome to the AutoIt forum. :D

Two ways I have automated menus:

1. If your app has accelerators (the underlined characters in the menus when you press Alt). You can use Send to open the menus initially and then either more accelerator keys to directly access the correct item, or a series of UP/DOWN/LEFT/RIGHT as required to move the cursor as if it were your mouse doing the work.

2. Use the _GUICtrlMenu UDF to find out about the menu. This will eventually give you the actual screen positions of the various menu items so you can then hit them with your MouseClick.

Personally I would go for the first method if at all possible. I have found it a good idea to add a short Sleep between the Send commands to allow the app menu to adjust - if you go too fast it does not have time to open submenus, etc.

I hope this helps. :huggles:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Mayur,

Welcome to the AutoIt forum. :D

Two ways I have automated menus:

1. If your app has accelerators (the underlined characters in the menus when you press Alt). You can use Send to open the menus initially and then either more accelerator keys to directly access the correct item, or a series of UP/DOWN/LEFT/RIGHT as required to move the cursor as if it were your mouse doing the work.

2. Use the _GUICtrlMenu UDF to find out about the menu. This will eventually give you the actual screen positions of the various menu items so you can then hit them with your MouseClick.

Personally I would go for the first method if at all possible. I have found it a good idea to add a short Sleep between the Send commands to allow the app menu to adjust - if you go too fast it does not have time to open submenus, etc.

I hope this helps. :huggles:

M23

Will you please explain first Method I didn't understand.

I tried second method but i am not able to get handle of menu because AutoIt Window Info doesnot recognises Menu Items.

I used first _GUICtrlNenu_GetMenu method first to get handle of Menu

& Then GUICtrlMenu_GetItemText this method returned blank.

Let me know Your Suggestions.

Thanks,

Mayur

Link to comment
Share on other sites

  • Moderators

Mayur,

Many apps have "accelerator" keys to open menus. Open Notepad and press the "Alt" key - on my version I can see small underlines in the menu like this:

File Edit Format View Help

These are the "accelerator" keys for the menu - if you now press "f", the <File> menu opens and you can see that there are more underlined characters in the sub-menu. Once again you can action an item by pressing the "accelerator" key - like "u" for <Page Setup>. So you can Send the keys directly to the app and have the menu open.

Some apps do not have "accelerators" for all the submenu items, or even at all. :huggles: In this case you might have to Send cursor keys to move to the correct item and then Send "Enter" to action it. To action the <Page Setup> item in Notepad this way would work something like this:

- Determine where the menu bar is situated on the GUI - convert this position to screen coordinates with _WinAPI_ClientToScreen.

- MouseClick on the menu bar to open it.

- Send down "Down" 5 times to get to the <Page Setup> item

- Send "Enter" to action it.

I hope that is clearer. :D

M23

P.S. When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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