BatMan22 Posted August 23, 2022 Posted August 23, 2022 (edited) Hi guys... So I have a GUI designed to be as 'universal' as possible.. and I am stuck on some weird behavior.. In my GUI I read a text box that is set to.. "SID,JF,{RIGHT},TC,SPACE,DF,ENTER" Each of those values correspond to an value for the program to type.. But when the values to enter get to be too long the program seems to "miss"? I have also tried _SendEx and it doesn't seem to help either.. But when I shorted to "SID,ENTER,SPACE" everything works fine and I can't figure out why I've even tried disabling commands and there's no difference.. Relevant Code Section: expandcollapse popupLocal $splitkeys = StringStripWS(GUICtrlRead($KeyInp), $STR_STRIPALL) ; Import in the Gui Control Text ConsoleWrite(@CRLF & "Splitkey start: " & $splitkeys) $splitkeys = StringSplit($splitkeys, ",", 2) ;Split into seperate actions _ArrayDisplay($splitkeys) ; Just for testing ;~ Exit For $i = 0 To UBound($splitkeys) - 1 ;Go through array of different actions and enter as needed Sleep(20) ConsoleWrite(@CRLF & "Splitkey is->" & $splitkeys[$i] & "<") If $splitkeys[$i] = "SIDM" Then If $Matrix <> "" Then _SendEx($SampleID) _SendEx(" " & $Matrix) Else _SendEx($SampleID) EndIf ElseIf $splitkeys[$i] = "SID" Then _SendEx($SampleID) ElseIf $splitkeys[$i] = "TC" Then _SendEx($TestCode) ElseIf $splitkeys[$i] = "DF" Then _SendEx("x" & $DF) ElseIf $splitkeys[$i] = "JF" Then _SendEx($JFlag & " ") ElseIf $splitkeys[$i] = "Space" Then _SendEx(" ") ElseIf $splitkeys[$i] = "ENTER" Then ;<-- MISSING KEYSTROKES ;~ Sleep(200) Send("{ENTER}") ElseIf $splitkeys[$i] = "{LEFT}" Then _SendEx("{LEFT}") ElseIf $splitkeys[$i] = "{RIGHT}" Then _SendEx("{RIGHT}") ElseIf $splitkeys[$i] = "{DOWN}" Then _SendEx("{DOWN}") ElseIf $splitkeys[$i] = "{UP}" Then _SendEx("{UP}") Else ConsoleWrite("NoMatchFound" & @CRLF) _SendEx($splitkeys[$i]) EndIf Next Also tested case and it seems similar in behavior expandcollapse popupFor $i = 0 To UBound($splitkeys) - 1 ConsoleWrite(@CRLF & "Splitkey is->" & $splitkeys[$i] & "<") Select Case $splitkeys[$i] = "SIDM" If $Matrix <> "" Then _SendEx($SampleID) _SendEx(" " & $Matrix) Else _SendEx($SampleID) EndIf Case $splitkeys[$i] = "SID" _SendEx($SampleID) Case $splitkeys[$i] = "TC" _SendEx($TestCode) Case $splitkeys[$i] = "DF" _SendEx("x" & $DF) Case $splitkeys[$i] = "JF" _SendEx($JFlag & " ") Case $splitkeys[$i] = "Space" _SendEx(" ") Case $splitkeys[$i] = "ENTER" Send("{ENTER}") Case $splitkeys[$i] = "{LEFT}" _SendEx("{LEFT}") Case $splitkeys[$i] = "{RIGHT}" _SendEx("{RIGHT}") Case $splitkeys[$i] = "{DOWN}" _SendEx("{DOWN}") Case $splitkeys[$i] = "{UP}" _SendEx("{UP}") Case Else ConsoleWrite("NoMatchFound" & @CRLF) _SendEx($splitkeys[$i]) EndSelect Next Edited August 23, 2022 by BatMan22
Zedna Posted August 23, 2022 Posted August 23, 2022 (edited) 1) Post source of _SendEx() 2) add some Sleep() after Send() 3) look here Edited August 23, 2022 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
Zedna Posted August 23, 2022 Posted August 23, 2022 Also be sure if you don't reuse/reset variable $i somewhere inside functions called from your For/Next loop where is $i declared Resources UDF ResourcesEx UDF AutoIt Forum Search
BatMan22 Posted August 23, 2022 Author Posted August 23, 2022 1) Post source of _SendEx() - see below 2) add some Sleep() after Send() - 100ms sleep didn't do anything 3) look here - Will check on this post 4) Also be sure if you don't reuse/reset variable $i somewhere inside functions called from your For/Next loop where is $i declared - don't see it, also console output confirms that it scrolls through every command, see below. expandcollapse popupWorking on*2208F65-001A*Testcode: 525.3_W DF IS: 1 JF Status is -> Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F66-001A 525.3_W 2208F66-001A<SampleID - JFlagRet>-1 2208F66-001A 525.3_W Working on*2208F66-001A*Testcode: 525.3_W DF IS: 1 JF Status is -> J-Flag Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F68-001A 525.3_W 2208F68-001A<SampleID - JFlagRet>0 2208F68-001A 525.3_W Working on*2208F68-001A*Testcode: 525.3_W DF IS: 1 JF Status is -> Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F70-001A 525.3_W 2208F70-001A<SampleID - JFlagRet>0 2208F70-001A 525.3_W Working on*2208F70-001A*Testcode: 525.3_W DF IS: 1 JF Status is -> Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F65-001A 525.3_W 2208F65-001A<SampleID - JFlagRet>0 2208F65-001A 525.3_W Working on*2208F65-001A*Testcode: 525.3_W DF IS: 3 JF Status is -> Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F66-001A 525.3_W 2208F66-001A<SampleID - JFlagRet>-1 2208F66-001A 525.3_W Working on*2208F66-001A*Testcode: 525.3_W DF IS: 3 JF Status is -> J-Flag Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F68-001A 525.3_W 2208F68-001A<SampleID - JFlagRet>0 2208F68-001A 525.3_W Working on*2208F68-001A*Testcode: 525.3_W DF IS: 3 JF Status is -> Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F70-001A 525.3_W 2208F70-001A<SampleID - JFlagRet>0 2208F70-001A 525.3_W Working on*2208F70-001A*Testcode: 525.3_W DF IS: 3 JF Status is -> Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE< SendEx source below: expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name ..........: _SendEx ; Description ...: alternative to built-in Send() function which prevents modifier keys from being left in a pressed state ; Syntax ........: _SendEx($sSendKeys[, $iTimeout[, $sReleaseKeys[, $hUser32Dll]]]) ; Parameters ....: $sSendKeys - string of keys to send in Send() format ; $hUser32Dll - [optional] handle to user32.dll ; $iTimeout - [optional] maximum time in ms to attempt to release pressed keys (minimum = 250) ; $sReleaseKeys - [optional] comma seperated string of keys to release before issuing Send() (no spaces). ; defaults to: Shift, Ctrl, Alt, L Win, R Win ; Return values .: Success returns 1, else sets @error to 1 and returns an error message string ; Release date ..: 25-May-2014 ; Modify date ...: 21-Sep-2014 ; Author ........: iCode ; Modified by ...: ; Remarks .......: ; Related .......: Send() ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _SendEx($sSendKeys, $hUser32Dll = "", $iTimeout = 2000, $sReleaseKeys = "0x10,0x11,0x12,0x5B,0x5C") Local $bCloseDll, $sRet Local $iDelay = Opt("SendKeyDelay") + Opt("SendKeyDownDelay") If $iDelay < 50 Then $iDelay = 50 Local $aReleaseKeys = StringSplit($sReleaseKeys, ",") If @error Then Return SetError(1, 0, "Failed to create release key array") If $hUser32Dll <> "user32.dll" Then $hUser32Dll = DllOpen("user32.dll") If @error Then Return SetError(1, 0, "Failed to open handle to user32.dll") $bCloseDll = True EndIf $sRet = __ReleaseKeys($aReleaseKeys, $iTimeout, $hUser32Dll) If Not @error Then Send($sSendKeys) Sleep($iDelay) $sRet = __ReleaseKeys($aReleaseKeys, $iTimeout, $hUser32Dll) EndIf If $bCloseDll Then DllClose("user32.dll") If $sRet Then Return SetError(1, 0, $sRet) Return 1 EndFunc ;==>_SendEx ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name ..........: __ReleaseKeys ; Description ...: release pressed keys ; Syntax ........: __ReleaseKeys(Byref $aReleaseKeys, $iTimeout, $hUser32Dll) ; Parameters ....: $aReleaseKeys - [in/out] An array of unknowns. ; $iTimeout - An integer value. ; $hUser32Dll - A handle value. ; Return values .: None ; Author ........: iCode ; Modified ......: 25-May-2014 ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __ReleaseKeys(ByRef $aReleaseKeys, $iTimeout, $hUser32Dll) If $iTimeout < 50 Then $iTimeout = 250 Local $aRet, $hTimer = TimerInit() For $i = 0 To UBound($aReleaseKeys) - 1 $aRet = DllCall($hUser32Dll, "short", "GetAsyncKeyState", "int", $aReleaseKeys[$i]) If @error Then Return SetError(1, 0, "Dll call GetAsyncKeyState failed with key: " & $aReleaseKeys[$i]) If BitAND($aRet[0], 0x8000) <> 0 Then Do Sleep(100) DllCall($hUser32Dll, "int", "keybd_event", "int", $aReleaseKeys[$i], "int", 0, "long", 2, "long", 0) If @error Then Return SetError(1, 0, "Dll call keybd_event failed with key: " & $aReleaseKeys[$i]) $aRet = DllCall($hUser32Dll, "short", "GetAsyncKeyState", "int", $aReleaseKeys[$i]) If TimerDiff($hTimer) >= $iTimeout Then Return SetError(1, 0, "Time out limit reached") Until BitAND($aRet[0], 0x8000) = 0 EndIf Next EndFunc ;==>__ReleaseKeys
BatMan22 Posted August 23, 2022 Author Posted August 23, 2022 (edited) @Zedna In reference to the link you posted, sending with Send("{ENTER}", $SEND_RAW) obviously types in {Enter} but it does prove that it doesn't miss when it's doing that. Also the control send is not available for this application, I wish it was. Also the problem persists with Send or _SendEx Edited August 23, 2022 by BatMan22
BatMan22 Posted August 23, 2022 Author Posted August 23, 2022 Just to rule it out, I also attempted a restart of the whole PC / Switched from $i to $m / Case vs If Else / Send vs _SendEx .... So confused on what is going on.
BatMan22 Posted August 24, 2022 Author Posted August 24, 2022 BUMP.. Also tried adding in coding below, hoping it was a language issue or something.. Global Const $iLanguage = 0x0409 Local $hWnd _WinAPI_GetKeyboardLayout($hWnd) _WinAPI_SetKeyboardLayout( $hWnd , $iLanguage )
Luke94 Posted October 14, 2022 Posted October 14, 2022 What are the values of $SampleID, $JFlag, $TestCode and $DF?
BatMan22 Posted October 17, 2022 Author Posted October 17, 2022 On 10/14/2022 at 1:08 PM, Luke94 said: What are the values of $SampleID, $JFlag, $TestCode and $DF? So the output above shows the general values (they change) but: $SampleID in this case is 2208F65-001A.. the general pattern remains the same but the values roll over with time JFlag is either 0,-1, or "J-Flag" or nothing TestCode is "525.3_W" or nothing Matrix is usually nothing, but sometimes "Water" or "Soil" Or "w" or "s" Working on*2208F65-001A*Testcode: 525.3_W DF IS: 1 JF Status is -> Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F66-001A 525.3_W 2208F66-001A<SampleID - JFlagRet>-1 2208F66-001A 525.3_W Working on*2208F66-001A*Testcode: 525.3_W DF IS: 1 JF Status is -> J-Flag Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F68-001A 525.3_W 2208F68-001A<SampleID - JFlagRet>0 2208F68-001A 525.3_W Working on*2208F68-001A*Testcode: 525.3_W DF IS: 1 JF Status is -> Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F70-001A 525.3_W 2208F70-001A<SampleID - JFlagRet>0 2208F70-001A 525.3_W Working on*2208F70-001A*Testcode: 525.3_W DF IS: 1 JF Status is -> Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F65-001A 525.3_W 2208F65-001A<SampleID - JFlagRet>0 2208F65-001A 525.3_W Working on*2208F65-001A*Testcode: 525.3_W DF IS: 3 JF Status is -> Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F66-001A 525.3_W 2208F66-001A<SampleID - JFlagRet>-1 2208F66-001A 525.3_W Working on*2208F66-001A*Testcode: 525.3_W DF IS: 3 JF Status is -> J-Flag Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F68-001A 525.3_W 2208F68-001A<SampleID - JFlagRet>0 2208F68-001A 525.3_W Working on*2208F68-001A*Testcode: 525.3_W DF IS: 3 JF Status is -> Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<2208F70-001A 525.3_W 2208F70-001A<SampleID - JFlagRet>0 2208F70-001A 525.3_W Working on*2208F70-001A*Testcode: 525.3_W DF IS: 3 JF Status is -> Matrix is : Splitkey start: DF,ENTER,SPACE Splitkey is->DF< Splitkey is->ENTER< Splitkey is->SPACE<
BigDaddyO Posted October 19, 2022 Posted October 19, 2022 everywhere you do a SendEX add a Consolewrite before it to show what is being sent to the SendEX so you can see if the issue is with what's being sent to SendEX or with what is being sent from it. Ex. Case $splitkeys[$i] = "SID" Consolewrite("_SendEx(" & $SampleID & ")" & @CRLF) _SendEx($SampleID) If the console outputs the expected value then the problem is with what is being sent from the _SendEx. Try putting this line at the top of your script to slow down the character input Opt("SendKeyDelay", 70)
BatMan22 Posted October 20, 2022 Author Posted October 20, 2022 18 hours ago, BigDaddyO said: everywhere you do a SendEX add a Consolewrite before it to show what is being sent to the SendEX so you can see if the issue is with what's being sent to SendEX or with what is being sent from it. Ex. Case $splitkeys[$i] = "SID" Consolewrite("_SendEx(" & $SampleID & ")" & @CRLF) _SendEx($SampleID) If the console outputs the expected value then the problem is with what is being sent from the _SendEx. Try putting this line at the top of your script to slow down the character input Opt("SendKeyDelay", 70) Console write matches expected output 100% of the time I'll try the SendKey Delay, thanks!
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