IQ9003 Posted June 4, 2007 Share Posted June 4, 2007 (edited) I need to wait for a menuitem to appear on the screen and then click on that item. I've managed to get the items and click on them, in my example I used a sleep(50) to send the Clickitem. But for the reliabilty in my program I want to wait for an item to appear on the screen and then click on an item. #include <A3LMenu.au3> Winwaitactive("TESTMACHINE","") $hWnd = WinGetHandle("TESTMACHINE") $hMenu = _Menu_GetMenu ($hWnd) If IsHWnd($hMenu) Then $ItemCnt = _Menu_GetItemCount($hMenu) $resultaat=0 for $i=0 to $ItemCnt If StringInStr(_Menu_GetItemText($hMenu, $i), "Acties") then $resultaat=$i endif next $resultaat2=0 $hFileMenu = _Menu_GetItemSubMenu($hMenu, $resultaat) $ItemCnt = _Menu_GetItemCount($hFileMenu) for $i=0 to $ItemCnt If StringInStr(_Menu_GetItemText($hFileMenu, $i), "Vo&lgblad") then $resultaat2=$i endif next _Menu_ClickItem($hWnd, $hMenu, $resultaat) sleep(50) _Menu_ClickItem($hWnd, $hFileMenu, $resultaat2) Sleep(50) endIf Can anyone help me? Edited June 4, 2007 by IQ9003 Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 4, 2007 Share Posted June 4, 2007 I need to wait for a menuitem to appear on the screen and then click on that item. I've managed to get the items and click on them, in my example I used a sleep(50) to send the Clickitem. But for the reliabilty in my program I want to wait for an item to appear on the screen and then click on an item. Can anyone help me? This mod loops until the first menu item appears, then checks for the subitem. Only when both appear do they get clicked and it exits the While/WEnd loop: expandcollapse popup#include <A3LMenu.au3> WinWaitActive("TESTMACHINE", "") $hWnd = WinGetHandle("TESTMACHINE") $hMenu = _Menu_GetMenu ($hWnd) If IsHWnd($hMenu) Then While 1 $ItemCnt = _Menu_GetItemCount ($hMenu) $resultaat = 0 For $i = 0 To $ItemCnt If StringInStr(_Menu_GetItemText ($hMenu, $i), "Acties") Then $resultaat = $i ExitLoop EndIf Next If $resultaat Then $resultaat2 = 0 $hFileMenu = _Menu_GetItemSubMenu ($hMenu, $resultaat) $ItemCnt = _Menu_GetItemCount ($hFileMenu) For $i = 0 To $ItemCnt If StringInStr(_Menu_GetItemText ($hFileMenu, $i), "Vo&lgblad") Then $resultaat2 = $i ExitLoop EndIf Next If $resultaat2 Then _Menu_ClickItem ($hWnd, $hMenu, $resultaat) Sleep(50) _Menu_ClickItem ($hWnd, $hFileMenu, $resultaat2) Sleep(50) ExitLoop EndIf EndIf WEnd Else MsgBox(16, "Error", "Invalid menu handle in $hMenu.") EndIf Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
IQ9003 Posted June 5, 2007 Author Share Posted June 5, 2007 Thanx for your reply.However my problem remains, I'm trying to get rid of the sleeps. I want to open a menu and then wait for an item before sending the next click.Because I have a main loop with ~400 records, therefore I don't want to wait with sleeps. (and sometimes the sleeps are to short and the main loop stops)Any other suggestions what I can do? Link to comment Share on other sites More sharing options...
IQ9003 Posted June 5, 2007 Author Share Posted June 5, 2007 Thanx for your reply.However my problem remains, I'm trying to get rid of the sleeps. I want to open a menu and then wait for an item before sending the next click.Because I have a main loop with ~400 records, therefore I don't want to wait with sleeps. (and sometimes the sleeps are to short and the main loop stops)Any other suggestions what I can do? Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 5, 2007 Share Posted June 5, 2007 However my problem remains, I'm trying to get rid of the sleeps. I want to open a menu and then wait for an item before sending the next click.Because I have a main loop with ~400 records, therefore I don't want to wait with sleeps. (and sometimes the sleeps are to short and the main loop stops)Sleeps? The only sleeps in my code are 50 miliseconds long and only get used when it's actually clicking on the menu items. Did you even try the code... flow chart it... read it... anything? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
IQ9003 Posted June 6, 2007 Author Share Posted June 6, 2007 Thanks you for you're response, and I have tryed the code and it works fine most of the time. However sometimes the scripts halts and I can see that the clicks are sent but the second click is too fast for the system. The program wich I'm trying to automate runs on a server, therefore the response between the first keystroke and the second isn't always constant. When I send the first key I need to wait till the menu is visible and only then I can send the second key. (sometimes the response can be ~1 second). _Menu_ClickItem ($hWnd, $hMenu, $resultaat) Sleep(50) _Menu_ClickItem ($hWnd, $hFileMenu, $resultaat2) Sleeps? The only sleeps in my code are 50 miliseconds long and only get used when it's actually clicking on the menu items. Did you even try the code... flow chart it... read it... anything? Link to comment Share on other sites More sharing options...
LondonNDIB Posted June 6, 2007 Share Posted June 6, 2007 Just in case it applies to your situation... any chance the application you're interacting with uses hotkeys for those menu items? LD Link to comment Share on other sites More sharing options...
IQ9003 Posted June 6, 2007 Author Share Posted June 6, 2007 Unfortunately the program doesn't use hotkeys for that function.Just in case it applies to your situation... any chance the application you're interacting with uses hotkeys for those menu items?LD Link to comment Share on other sites More sharing options...
LondonNDIB Posted June 6, 2007 Share Posted June 6, 2007 yeah, that would have been too easy good luck! Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 6, 2007 Share Posted June 6, 2007 Thanks you for you're response, and I have tryed the code and it works fine most of the time. However sometimes the scripts halts and I can see that the clicks are sent but the second click is too fast for the system. The program wich I'm trying to automate runs on a server, therefore the response between the first keystroke and the second isn't always constant. When I send the first key I need to wait till the menu is visible and only then I can send the second key. (sometimes the response can be ~1 second). Then you need a longer Sleep() in my code. Again, since the sleep only gets used when the actual clicking happens, it shouldn't be a total execution time issue. Give it enough time from the first item click to the second to make it reliable: _Menu_ClickItem ($hWnd, $hMenu, $resultaat) Sleep(1000) ; 1sec delay _Menu_ClickItem ($hWnd, $hFileMenu, $resultaat2) Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
herewasplato Posted June 6, 2007 Share Posted June 6, 2007 I need to wait for a menuitem to appear on the screen and then click on that item...Then you may have to use one of the pixel functions:pixel... = xactivate menudosleepuntil not pixel = x-MSP- [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
IQ9003 Posted June 6, 2007 Author Share Posted June 6, 2007 Thanks for your reply, it works! With the PixelChecksum I'm able to detect a change on the screen. $checksum = PixelChecksum(20,90, 90,250) _Menu_ClickItem ($hWnd, $hMenu, $resultaat) While $checksum = PixelChecksum(20,90,90,250) Sleep(10) WEnd Then you may have to use one of the pixel functions: pixel... = x activate menu do sleep until not pixel = x -MSP- Link to comment Share on other sites More sharing options...
herewasplato Posted June 6, 2007 Share Posted June 6, 2007 Thanks for your reply, it works!Great and you are welcome... [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now