Jorge11 Posted May 24, 2018 Posted May 24, 2018 I'm working on a script using Yashied's HotKey UDF (which I like more than AutoIt standard hotkeys), for more easy control of some other application. To do what I very often want with this other appl, I normally have to first press two separate keys (ALT + some letter), so I use the HotKey UDF mainly to be able to press a single Fkey instead of pressing two keys. But sometimes the other appl will pop-up anotther subwindow asking something, like to confirm the thing I asked for. But since that doesn't happen every time, I don't know the right way to handle that. Here's the kind of thing I've tried, but it fairly often gets messed up and stops working / stops responding to the Fkeys: expandcollapse popup#include <Array.au3> #include <Constants.au3> #include <Misc.au3> #include "HotKey_21b.au3" #include "vkConstants.au3" AutoItSetOption("MustDeclareVars", 1) AutoItSetOption("WinTitleMatchMode", 2) AutoItSetOption("GUIOnEventMode", 1) SetupHotkeys() Do Sleep( 10 ) Until False Exit ; ;================================ ; Func SetupHotkeys() _HotKey_Assign( $VK_F8, "Copy_File", $HK_FLAG_DEFAULT ) _HotKey_Assign( $VK_F9, "Move_File", $HK_FLAG_DEFAULT ) _HotKey_Assign( $VK_F10, "CloseThis", $HK_FLAG_DEFAULT ) _HotKey_Enable() EndFunc ; ;================================ ; Func CloseThis() ; Clear hotkeys and exit _HotKey_Disable() _HotKey_Release() Exit EndFunc ; ;================================ ; Func Copy_File() Local $iStat, $whMain, $whSubwin, $bSubWinReady, $iSubWinLoopCount If ProcessExists( "OtherProgram.exe" ) = 0 Then Return $whMain = WinActive( "Other" ) If $whMain = 0 Then $whMain = WinActivate( "Other" ) If $whMain = 0 Then Return EndIf EndIf $iStat = ControlSend( $whMain, "", "", "!c" ) If $iStat <> 1 Then Return EndIf $iSubWinLoopCount = 0 $bSubWinReady = False While (Not $bSubWinReady) And ($iSubWinLoopCount < 30) $whSubwin = WinActive( "Copy To Folder" ) If $whSubwin = 1 Then $bSubWinReady = True Else $whSubwin = WinWaitActive( "Copy To Folder", "", 1 ) If $whSubwin <> 0 Then $bSubWinReady = True Else $iSubWinLoopCount += 1 $iStat = ControlSend( $whMain, "", "", "!c" ) If $iStat <> 1 Then Return EndIf EndIf EndIf WEnd If Not $bSubWinReady Then ;too many times through loop Return EndIf $iStat = ControlClick( $whSubwin, "", "OK" ) If $iStat <> 1 Then Return EndIf $iSubWinLoopCount = 0 $bSubWinReady = False While (Not $bSubWinReady) And ($iSubWinLoopCount < 3) $whSubwin = WinActive( "Confirm File Replace" ) If $whSubwin = 1 Then $bSubWinReady = True Else $whSubwin = WinWaitActive( "Confirm File Replace", "", 1 ) If $whSubwin <> 0 Then $bSubWinReady = True Else $iSubWinLoopCount += 1 EndIf EndIf WEnd If $bSubWinReady Then ;If the subwindow DID appear Sleep( 200 ) $iStat = ControlClick( $whSubwin, "", "[ID:3746]" ) ; Press "Skip" button If $iStat <> 1 Then Return EndIf EndIf Return EndFunc ; ;================================ ; Func Move_File() Local $iStat, $whMain, $whSubwin, $bSubWinReady, $iSubWinLoopCount If ProcessExists( "OtherProgram.exe" ) = 0 Then Return $whMain = WinActive( "Other" ) If $whMain = 0 Then $whMain = WinActivate( "Other" ) If $whMain = 0 Then Return EndIf EndIf $iStat = ControlSend( $whMain, "", "", "!m" ) If $iStat <> 1 Then Return EndIf $iSubWinLoopCount = 0 $bSubWinReady = False While (Not $bSubWinReady) And ($iSubWinLoopCount < 30) $whSubwin = WinActive( "Move To Folder" ) If $whSubwin = 1 Then $bSubWinReady = True Else $whSubwin = WinWaitActive( "Move To Folder", "", 1 ) If $whSubwin <> 0 Then $bSubWinReady = True Else $iSubWinLoopCount += 1 $iStat = ControlSend( $whMain, "", "", "!m" ) If $iStat <> 1 Then Return EndIf EndIf EndIf WEnd If Not $bSubWinReady Then ;too many times through loop Return EndIf $iStat = ControlClick( $whSubwin, "", "OK" ) If $iStat <> 1 Then Return EndIf $iSubWinLoopCount = 0 $bSubWinReady = False While (Not $bSubWinReady) And ($iSubWinLoopCount < 3) $whSubwin = WinActive( "Confirm File Replace" ) If $whSubwin = 1 Then $bSubWinReady = True Else $whSubwin = WinWaitActive( "Confirm File Replace", "", 1 ) If $whSubwin <> 0 Then $bSubWinReady = True Else $iSubWinLoopCount += 1 EndIf EndIf WEnd If $bSubWinReady Then ;If the subwindow DID appear Sleep( 200 ) $iStat = ControlClick( $whSubwin, "", "[ID:3746]" ) ; Press "Skip" button If $iStat <> 1 Then Return EndIf EndIf Return EndFunc But maybe this whole idea is no good. What would be a better way, please.
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