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

WoodGrain

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
SadBunny

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
WoodGrain

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
WoodGrain

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
SadBunny

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

 

  • Like 1

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

Share this post


Link to post
Share on other sites
WoodGrain

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

Share this post


Link to post
Share on other sites
WoodGrain

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
SadBunny

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
SadBunny
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
WoodGrain

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
SadBunny

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
JustSomeone

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

    • TheDcoder
      By TheDcoder
      Hello everyone, long time since I made a post in the H&S sub-forum
      I am working on a project where in a situation I would have to hold down an arrow key and release it in another statement/command, however when I wrote the code it isn't working exactly like I thought it would. Here is an example:
      Send("{UP down}") Sleep(10000) Send("{UP up}") This should hold the up arrow key for 10 seconds before releasing it again, but when I run this code the cursor in SciTE moves up only once
      If I hold the up arrow manually for 10 seconds it "repeats" and the cursor moves up several times until I release the key... Is this a known limitation of Send? Is there any other way I can accomplish this?
      Thanks for all the help and feedback in advance! TD
    • guner7
      By guner7
      Hi everyone,
      I would like to share a simple snippet where I use for my hotkey script.
      I was searching for a solution whereby pressing a same key, I could have different outcome according to the way the key is being pressed.
      1) Double tap/press fast (like double click the mouse) - outcome A
      2) Long press or HOLD for awhile (2-4 sec) - outcome B
      #Include <Timers.au3> Global $interval_timer, $counter HotKeySet("{F10}", "_terminate") While 1 Sleep(10) WEnd Func _terminate() Local $itv_timer $itv_timer = _Timer_Diff($interval_timer) $interval_timer = _Timer_Init() ;ConsoleWrite($itv_timer & @CRLF) ;to review the timer difference so I can decide the range to capture double tap sequence If $itv_timer > 100 And $itv_timer < 250 Then $counter = 0 $interval_timer = _Timer_Init() MsgBox("","","double tap detected") Elseif $counter >= 25 Then $counter = 0 $interval_timer = _Timer_Init() MsgBox("","","long press detected") ElseIf $itv_timer < 50 Then $counter = $counter + 1 ConsoleWrite($counter & @CRLF) Else $counter = 0 EndIf EndFunc The trick here is to collect and use the frequency of the hotkey is called, and the time difference between each time the hotkey is being called.
      My coding style is not efficient and can be such a mess most of the time, any suggestion or better coding are welcome.
      I hope you find this one helpful.
    • 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?
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.