Sign in to follow this  
Followers 0
WoodGrain

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

12 posts in this topic

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

 

1 person likes this

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

Share this post


Link to post
Share on other sites

Oh, that's very helpful, thanks!
Trying again...

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  
Followers 0

  • Similar Content

    • badcoder123
      By badcoder123
      Anyone know how to access the information circled in the photo?
       

    • AndreyS
      By AndreyS
      Dear developers and creators of the language, please explain to me why when pressing the combination Crtl + Shift + C from the 5th or the 10th time "sticks / sinks" Ctrl or Shift? And then you need to press Ctrl or Shift again to reset their triggering. I only need to use hot keys like in the example!
      The code is a small example. Its essence is that when a user in the editor selects any number and presses a combination, then it increases by 1. 
      Dim $x HotKeySet("+^c","Calc") While 1 Sleep(10000) WEnd Func Calc() Send("^c") Sleep(50) $x=ClipGet()+1 ClipPut($x) Send("^v") EndFunc I thought that in my program some kind of glitch was searching for a reason for a long time. And it turned out that apparently somehow the work of some functions used in the example is not compatible. 
      Tell me, please, what is the problem?
    • AndreyS
      By AndreyS
      Hello to you, dear developers!
      Could you please tell me if there is an easy way to determine if the information was pasted from the clipboard?
      Without any variation of the insertion via Ctrl+V, or through the context menu.
      I revised the Help and many forum topics, but found nothing suitable.
      Can there be any WinAPI system events that determine this event?
    • ur
      By ur
      If you observe in below code.
      Func _WinWaitActivate($title,$text,$timeout=$time_out) Logging("Waiting for "&$title&":"&$text) $dHandle = WinWait($title,$text,$timeout) if not ($dHandle = 0) then If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) Else Logging("Timeout occured while waiting for the window...") Exit EndIf EndFunc WinActivate("Untitled - Notepad") $p = "Notallowed1!!" Send("{ENTER}{ENTER}{ENTER}{ENTER}"& $p &"{ENTER}create{SPACE}database{SPACE}"& $p &";{ENTER}") In the notepad if you observe, ! is missing in the text got.
       
      Is there way to get that also printed.
    • Byte11
      By Byte11
      WinSetState ("[CLASS:OpusApp]", "", @SW_SHOWMAXIMIZED) and WinSetState ("[CLASS:OpusApp]", "", @SW_MAXIMIZE) don't maximize the window.  Using WinSetState("[CLASS:OpusApp]","",@SW_RESTORE) allows me to maximize it about 15% of the time. I've tried using  WinMove("[active]",0,0,@Desktopwidth,@Desktopheight), but that only makes it worse. I've also tried putting in a sleep and maximizing it again. Does anyone have a solution?
      Here's my code:
      The startup script is intentionally commented, because I'm not testing it right now. The other comment is just for debugging when I need it. 
       
      UPDATE: When I run two instances of the program, it works almost all the time, but if I copy the code inside the else statement twice it doesn't work at all (despite the fact that it's running the same code just in one program vs two). I also noticed that when I run two instances of it, about 50% of the time when it opens both the windows, it also hits the windows button and types the letter d into the search box. Neither of these actions are in my code. I'm not really sure what's going on.