Menu selection for non-standard menus

Some Windows applications do not implement menu design using the standard Windows API functions, and then the WinTask Choosemenu function does not work properly.

If menu options can be accessed through keyboard sortcuts, use them for recording your menu selections and then to replay, for example the File/Save menu in Excel 2007 can be automatized using this code:

UseWindow("EXCEL.EXE|EXCEL7|")
SendKeys("<Alt F>")
pause 10 ticks
SendKeys("S",Noactivate)

But, a software can have no shortcuts : the script below shows how we can still automate menu selections.

 

 

sub init_menu()

 

'This function defines each menu option with two numbers separated by a pipe ("|").

'First one gives the horizontal order number of the option.

'The second one gives the vertical number when the full menu is displayed

'As an example, we show those numbers for the first two Notepad menus (File and Edit) :

 

FileNew$="00|00"

FileOpen$="00|01"

FileSave$="00|02"

FileSaveas$="00|03"

FilePageSetup$="00|04"

FilePrint$="00|05"

FileExit$="00|06"

 

EditUndo$="01|00"

EditCut$="01|01"

EditCopy$="01|02"

EditPaste$="01|03"

EditDelete$="01|04"

EditSelectAll$="01|05"

EditTimeDate$="01|06"

EditWordWrap$="01|07"

EditSetFont$="01|08"

 

 

EndSub

 

'--------------------------------------------

Function Calc_Menu(menu$)

local buffer$

 

buffer$=menu$

if buffer$="" then

msgbox("Error menu option")

stop

endif

pos=instr(buffer$,"|")

if pos=0 then

msgbox("Error menu option")

stop

endif

menu1=val(left$(buffer$,pos-1))

menu2=val(right$(buffer$,len(buffer$)-pos))

EndFunction

 

'--------------------------------------------

Function Select_menu(menu$)

Calc_Menu(menu$)

UseWindow(fen_princ$)

sendkeys("<Alt>")

pause 5 ticks

if menu1 <> 0 then

i=0

repeat

sendkeys("<Right>")

pause 5 ticks

i=i+1

until i=menu1

endif

sendkeys("<Enter>")

 

if menu2 <> 0 then

i=0

repeat

sendkeys("<Down>")

pause 5 ticks

i=i+1

until i=menu2

endif

sendkeys("<Enter>")

endfunction

'*******************************************************

'MAIN PROGRAM

'*******************************************************

 

'launch notepad

shell("notepad.exe")

 

'define your main window

fen_princ$="NOTEPAD.EXE|Notepad|Untitled - Notepad"

 

'init menus

init_menu()

 

'call one option

EditCDL$=EditSetFont$

Select_menu(EditCDL$)