Jump to content
Sign in to follow this  
WoodGrain

Send Raw is driving me INSANE - What am I doing wrong or is this a bug?

Recommended Posts

Hi All,

Could someone please PLEASE tell me what I'm doing wrong here?
I feel like I'm close to figuring this out, I think I've identified what is causing the issue.

Whenever I try to use the hotkey CTRL+SHIFT+T (or any other letter other than T for that matter) to paste the text to notepad, my CTRL and SHIFT keys are held down *IF* I release them *WHILE* the raw text is being written.

It seems to be that if I release the CTRL+SHIFT keys:

  • Before the Send Raw text starts to write to the screen: the CTRL and SHIFT keys ARE NOT held down, this is good
  • During the Send Raw text being written to the screen: the CTRL and SHIFT keys ARE held down perpetually until I physically press them on the keyboard, this is bad
  • After the Send Raw text has written all text to the screen: the CTRL and SHIFT keys ARE NOT held down, this is good

This is also the case if I were to use the Windows Key as the hot key instead of the CTRL+SHIFT, I would need to tap the WIN key physically on my keyboard if I released it while the raw tet was being sent to the screen (eg, WIN+T).

This issue also happens no matter which program I try to write the text to.

Here's some example code:
(I've put a bunch of "a's" in there to give enough time to test releasing the CTRL+SHIFT before/during/after the writing of them)

HotKeySet("^+t", "WriteTxt")

Func WriteTxt()
   WinWaitActive("Untitled - Notepad")
   $var = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
   send($var, 1)
EndFunc

While 1
   Sleep(500)
WEnd

Thanks guys!

Share this post


Link to post
Share on other sites

I can reproduce, but only the first time I use the hotkey after the script start. If I then press CTRL+SHIFT once it jiggles it loose and everything is fine again, after that the hotkey works fine. These kinds of problems happen often when combining hotkeys and send functions.

Problem seems to go away if I do what I always do with hotkey functions: un-set the hotkey when entering the function, then re-set it when it's done:

HotKeySet("^+t", "WriteTxt")

Func WriteTxt()
    HotKeySet("^+t")
    WinWaitActive("Untitled - Notepad")
    $var = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    Send($var, 1)
    HotKeySet("^+t", "WriteTxt")
EndFunc   ;==>WriteTxt

While 1
    Sleep(500)
WEnd

 


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Thanks SB!

I have found it to repeat on 2 computers I've used, but randomly.

Very interesting, I will try your suggestion to un-set/re-set - thanks!

Share this post


Link to post
Share on other sites

Hmm, nope, same issue, after releasing the hotkey and re-setting it.
If I release the CTRL+SHIFT keys *while* the text is being written it still hold them down :(

Share this post


Link to post
Share on other sites

Yeah, it's just not all that reliable, which is why in every topic where send comes up as a means to automation, people suggest to try and find another way to automate.

As an added precautionary measure against conflicts, you could (should, IMHO :) ) also always make theese functions wait until you release all keys in the combo. Especially when you combine stuff with Send. So in this case:

#include <Misc.au3>

HotKeySet("^+t", "WriteTxt")

Func WriteTxt()
    HotKeySet("^+t")
    While _IsPressed(10) Or _IsPressed(11) Or _IsPressed(54) ; <-- wait as long as any key of the ^+t combo is still pressed
        Sleep(10)
    WEnd
    WinWaitActive("Untitled - Notepad")
    $var = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    Send($var, 1)
    HotKeySet("^+t", "WriteTxt")
EndFunc   ;==>WriteTxt

While 1
    Sleep(500)
WEnd

 


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

WINNER!!!
Thanks SB!

Obviously they can press the keys again while the text is being written, but that is extremely unlikely (tho I've found it is amazing what ppl can accomplish).

BTW, you mentioned "people suggest to try and find another way to automate", within AutoIT or via other programming?

Share this post


Link to post
Share on other sites

Cool :) 

2 minutes ago, WoodGrain said:

BTW, you mentioned "people suggest to try and find another way to automate", within AutoIT or via other programming?

It's mostly to do with things like pressing tab five times to get to a button, while there's also things like ControlSend or ControlClick etc. to directly interact with a control which is much more reliable and much less prone to accidental conflicts with the user.


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
7 minutes ago, WoodGrain said:

Obviously they can press the keys again while the text is being written

Well, they could press it, but that's exactly why I unset the hotkey at the beginning of the function and then reset it at the end - while the function is running, the hotkey won't work, and the Send command halts the script until it is done (try adding opt("SendKeyDelay", 50) on top of your script to see it clearly - use the hotkey during the aaaa... sending and it won't do anything until the send is complete).


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Oh, I mean they could press and release CTRL and/or SHIFT while the send raw is writing, disregarding the full CTRL+SHIFT+T combination, this causes the key(s) to be pressed down indefinitely.

Share this post


Link to post
Share on other sites

Well, if it's about notepad or anything else using easy-to-automate windows controls, something like this would not be affected by ctrl/shift being held down:

ControlSend("Untitled - Notepad", "", "[CLASS:Edit; INSTANCE:1]", "some text to send")

 


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

My 2 cents while reading this:

Autoit options SendKeyDelay and SendKeyDownDelay should be checked when using send(). Some programs do require a bit (say 50 ms down and 30 between keys) more time so they register an actual button being pressed. If you send for example "someverylongstring" you may end up with "smeerylongstrng" or similar. Again , it really depends to what program you are sending text/buttons etc :)

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • By BetaLeaf
      What is Rollbar?
      Rollbar provides real-time error alerting & debugging tools for developers. Learn more about it at https://rollbar.com/product/
      Demo: https://rollbar.com/demo/demo/
      Screenshot:
      Instructions: (RollbarTest.au3)
      ; Include RollbarSDK #include "RollbarSDK.au3" ;Turns on ConsoleWrite debugging override. ;Global $Rollbar_Debug=False ; Initialize RollbarSDK with the project's API key. ; Parameters ....: $__Rollbar_sToken - [Required] Go to https://rollbar.com/<User>/<ProjectName>/settings/access_tokens/ for your project. Use the token for post_server_item. _Rollbar_Init("eaa8464a4082eeabd9454465b8f0c0af") ; Write code that causes an error you want to catch, then call ; _Rollbar_Send ; Parameters ....: $__Rollbar_sErrorLevel - [Required] Must be one of the following values: Debug, Info, Warning, Error, Critical. ; $__Rollbar_sMessage - [Required] The message to be sent. This should contain any useful debugging info that will help you debug. ; $__Rollbar_sMessageSummary - [Optional] A string that will be used as the title of the Item occurrences will be grouped into. Max length 255 characters. If omitted, Rollbar will determine this on the backend. _Rollbar_Send("Debug", "This is an debug message. If you received this, you were successful!", "Debug Message") _Rollbar_Send("Info", "This is a test message. If you received this, you were successful!", "Info Message") _Rollbar_Send("Warning", "This is an warning message. If you received this, you were successful!", "Warning Message") _Rollbar_Send("Error", "This is an error message. If you received this, you were successful!", "Error Message") _Rollbar_Send("Critical", "This is an critical message. If you received this, you were successful!", "Critical Message") _Rollbar_Send("Info", "This is a test message. If you received this, you were successful!") ;No Message ; Rollbar_Send's helper functions ; Parameters ....: $__Rollbar_sMessage - [Required] The message to be sent. This should contain any useful debugging info that will help you debug. ; $__Rollbar_sMessageSummary - [Optional] A string that will be used as the title of the Item occurrences will be grouped into. Max length 255 characters. If omitted, Rollbar will determine this on the backend. _Rollbar_SendDebug("This is an debug message. If you received this, you were successful!", "Debug Message") _Rollbar_SendInfo("This is a test message. If you received this, you were successful!", "Info Message") _Rollbar_SendWarning("This is an warning message. If you received this, you were successful!", "Warning Message") _Rollbar_SendError("This is an error message. If you received this, you were successful!", "Error Message") _Rollbar_SendCritical("This is an critical message. If you received this, you were successful!", "Critical Message") ; Usable Example Local $sImportantFile = "C:\NOTAREALFILE_1234554321.txt" Switch FileExists($sImportantFile) Case True MsgBox(0, "Example Script", "An important file was found. Continuing...") Case Else _Rollbar_SendCritical('An important file was missing. Halting... File: "' & $sImportantFile & '"', 'Important file "' & $sImportantFile & '" is missing.') EndSwitch Notes: Please comment your feedback, advice, & suggestions below. While this is only a proof of concept, I will expand its feature set for everyone to use. 
      Right now, it is fully functional but not tested in production.
       
       
      Changelog:
      RollbarSDK.au3
      RollbarTest.au3
      v0.2
       
      v0.1.1
       
    • By XinYoung
      Hello all!   I'm stuck at a seemingly simple part of my script. Using IE, I'm filling out a web form that involves clicking a "Browse" button and selecting a file. Once the file explorer dialog opens, however, I am unable to control it.
      I have a string, which is the name of the file I want, and I'm trying to insert it into the 'File name:' text box in the dialog (which already has focus), but it doesn't get inserted. I've tried ClipPut and Send. 

      What's even more concerning is, when I close the dialog, the string is then pasted into the very next window that has focus, which is often SciTE. It's like that Browse's file open dialog halts all processes. Once it's closed, the script continues.
      ;~ Open a IE window and navigate to the login page. Global $oIE = _IECreate($urlBBLogin) _IELoadWait($oIE) ;~ Recognize the form on this page (login input boxes). Local $oForm = _IEFormGetObjByName($oIE, "login") Local $oTextLogin = _IEFormElementGetObjByName($oForm, "user_id") Local $oTextPass = _IEFormElementGetObjByName($oForm, "password") ;~ Enter the Automation user credentials into the form. _IEFormElementSetValue($oTextLogin, $bbUsername) _IEFormElementSetValue($oTextPass, $bbPassword) ;~ Click the Login button. _IEFormSubmit($oForm) _IELoadWait($oIE) ;~ Navigate to the feedfile upload page. _IENavigate($oIE, $urlUpload) _IELoadWait($oIE) ;~ Click the Browse button Local $Browse = _IEGetObjById($oIE, "feedFile_chooseLocalFile") _IEAction($Browse, "Click") Local $Browse = WinWait("Choose File to Upload") ;~ Open the file we created. WinActivate($Browse) Send($finalFile) Has anyone else experienced this problem? Any ideas to get around it? Am I approaching this the wrong way?
      Any support is greatly appreciated.
      Thank you.
    • By XinYoung
      HI! ... this is a big one (at least for me) 
      You guys previously helped me copy the used range in column A and paste them into a Website one at a time in a loop. Cool! Now, for another function, I have 2 columns, A and B, and two input boxes in the Website. I'm having a hard time replicating the loop for the 2 columns. 
      This is how I'm opening the Excel workbook (copied from the previous function that only had 1 column). I need to also get the used range in column B.
      Func OpenExcelForCopy() Global $aBBTableData Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen($oExcel, $ChosenFileName, Default, True, True) $oExcel.Sheets("CopyCourses").Activate ;~ Get all used cells in column A:A Global $aSearchItems = _Excel_RangeRead($oWorkbook, 1, $oWorkbook.Sheets("CopyCourses").Usedrange.Columns("A:A")) ;~ Duplicate the $aSearchItems Array Global $aSearchResult = $aSearchItems ;~ Loop through the array starting at 0 until the end of the array which is (Ubound($aSearchItems) - 1) For $i = 0 To UBound($aSearchItems) - 1 $aSearchResult[$i] = SearchCourseForCopy($aSearchItems[$i]) Next _Excel_RangeWrite($oWorkbook, Default, $aSearchResult, "C1") Finished() EndFunc ;==>OpenExcelForCopy Then we eventually get here. I don't think anything needs to change here but I'm not sure. This is where I paste the data from Column A into an input field (which is a search tool in a website). If the search is good, then we get to the tricky part...
      ;~ OK, we logged in and we searched for a course. Lets COPY it! Func CopyCourseBegin() Local $sResult $iSearchIndex = _ArraySearch($aBBTableData, "Course ID", 0, 0, 0, 1, 1, 0) ;~ If the course was not found, do this. If $iSearchIndex = -1 Then ;~ MsgBox(4096, "Search Error", "Item not found") $sResult = "Source Not Found" _Excel_RangeWrite($oWorkbook, Default, $aSearchResult, "C1") ;~ Now go back to the Excel sheet and search for the next one. ;~ If the course was found, begin the COPY process. Else For $i = 0 To UBound($aSearchItems) - 1 $aSearchResult[$i] = CopyCourseNow($aSearchItems[$i]) Next $sResult = "Copied" _Excel_RangeWrite($oWorkbook, Default, $aSearchResult, "C1") EndIf Return $sResult EndFunc ;==>CopyCourseBegin This is the "tricky part" where I'm confused. I can copy and paste what's in column A just fine, but I can't manage to replicate it for column B. I need to paste whats in Column B into "destinationCourseId"
      ;~ The course search was successful. COPY the course now. Func CopyCourseNow($_sSearchResult) ;~ Navigate to the course copy page. _IENavigate($oIE, $urlBBCourseCopy) ;~ Copy the SOURCE course ID from the Excel sheet ;~ Paste whats copied from column A into the Source Course ID text box Local $oForm = _IEGetObjByName($oIE, "selectCourse") Local $oSearchString = _IEFormElementGetObjByName($oForm, "sourceCourseId") _IEFormElementSetValue($oSearchString, $_sSearchResult) ;~ Paste whats copied from column B into the Destination Course ID text box ?!?!?!?! Local $oForm = _IEGetObjByName($oIE, "selectCourse") Local $oSearchString = _IEFormElementGetObjByName($oForm, "destinationCourseId") _IEFormElementSetValue($oSearchString, $_sSearchResult) ;~ Just exit cause im stuck :( _Exit() EndFunc ;==>CopyCourseNow After I paste the data from column A into "sourceCourseId" and column B into "destinationCourseId", I'll make it do some stuff. Then I need it to loop around until the used ranges in column A & B is finished.
      Does the entire code need to change now that there's two columns?
       
       
    • By Rhidlor
      I was wondering if there was a library or something which provides the capability to Send() to inactive windows, and I know what you're thinking, I could just use ControlSend(); the reason I can't use that in this situation is because I need to hold down keys for specific prolonged periods of time. Also activating the window, Send()ing then de-activating the window isn't really an option here, I need the target window to always be in the background. I've looked around the forums for an adequate amount of time and didn't find anything useful, perhaps because the threads were all 10 years old, nevertheless, if anyone has any suggestions they would be greatly appreciated.
      Thanks!
    • By qsek
      Im not sure if this is intended but normally Autoit variables are always passed as copies (except objects i think).
      But below i observed an unconsistency when copying maps with nested maps inside.
      Issue:
      If you create a nested map1 and copy it to a new map2, changing a nested value in map2 will also change the nested value in map1
      Dim $player[] Dim $sub[] $player.test1 = 1 $player.test2 = $sub $player.test2.child1 = "org" $player.test2.childext = $sub $player.test2.childext.child1 = "org2" $playerold = $player ; make a copy of the whole map ConsoleWrite("player.test2.child1 : "& $player.test2.child1 & @CRLF); original nested value in $player $playerold.test2.child1 = "changed" ; edit a nested value in $playerold ConsoleWrite("player.test2.child1 : "& $player.test2.child1 & @CRLF) ; original nested value in $player changed ConsoleWrite("---------------------" & @CRLF) ConsoleWrite("player.test2.childext.child1 : "& $player.test2.childext.child1 & @CRLF); original level2 nested value in $player $playerold.test2.childext.child1 = "changed2" ; edit a level2 nested value in $playerold ConsoleWrite("player.test2.child1 : "& $player.test2.child1 & @CRLF); original level1 nested value in $player stayed the same ConsoleWrite("player.test2.childext.child1 : "& $player.test2.childext.child1 & @CRLF); original level2 nested value in $player changed  
×
×
  • Create New...