WoodGrain Posted August 2, 2016 Posted August 2, 2016 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!
SadBunny Posted August 2, 2016 Posted August 2, 2016 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.
WoodGrain Posted August 2, 2016 Author Posted August 2, 2016 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!
WoodGrain Posted August 2, 2016 Author Posted August 2, 2016 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
SadBunny Posted August 2, 2016 Posted August 2, 2016 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 WoodGrain 1 Roses are FF0000, violets are 0000FF... All my base are belong to you.
WoodGrain Posted August 2, 2016 Author Posted August 2, 2016 Oh, that's very helpful, thanks! Trying again...
WoodGrain Posted August 2, 2016 Author Posted August 2, 2016 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?
SadBunny Posted August 2, 2016 Posted August 2, 2016 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.
SadBunny Posted August 2, 2016 Posted August 2, 2016 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.
WoodGrain Posted August 2, 2016 Author Posted August 2, 2016 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.
SadBunny Posted August 3, 2016 Posted August 3, 2016 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.
JustSomeone Posted August 4, 2016 Posted August 4, 2016 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
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