[HELP] Its adding an extra.. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
stream3366
Posts: 26
Joined: 16 Nov 2015, 17:12

[HELP] Its adding an extra..

03 Oct 2023, 14:24

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#NoEnv
#SingleInstance
#Persistent
SendMode Input
SetWorkingDir %A_ScriptDir%

`::
loop, 9 {
c := a_index
while (strlen(c) < 3)
	c := "0" c
SendInput, % c
sleep, 250
MouseMove 400, 1110
Sleep, 500
Click
Sleep, 100
Click
sleep, 2000
MouseMove, 300, 770
Sleep, 500
Click
Sleep, 500
SendInput, {Backspace 3}
Sleep 500
}

Esc::
Reload
return
it works fine when it is run through windows notepad, but when i run it on scrcpy to send commands to my android phone it keeps adding an extra number, the first number, so instead of typing "001" it types "001" then deletes the whole 3 numbers then types in "0" and then continues on to the MouseMove. help
User avatar
andymbody
Posts: 996
Joined: 02 Jul 2017, 23:47

Re: [HELP] Its adding an extra..

03 Oct 2023, 17:46

1. Can you post a screenshot of your screen when notepad is receiving input?
2. Then also a screenshot of when scrcpy is receiving input?
3. Also the resolution of your screen?

Just a guess, but I suspect it has something to do with the difference between the two windows. The mouseMove positions will be relative to the active window by default, rather than the screen.

You can try adding the following to the top of your script to see if you get different results
CoordMode, Mouse, Screen

And make sure the mouse x and y are accurate for the scrcpy window (in screen coordinates)
sofista
Posts: 654
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: [HELP] Its adding an extra..  Topic is solved

03 Oct 2023, 17:57

Besides @andymbody's advice, try this other code and see if it helps:

Code: Select all

Loop, 9 {
	SendInput, % Format("{:03}", A_Index)
	; ...
}
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: [HELP] Its adding an extra..

03 Oct 2023, 19:52

If you have inconsistent sends try:

Code: Select all

SetKeyDelay, 50, 50

Send, % c
or:

Code: Select all

SetKeyDelay, 50, 50

Send, % "{text}" . c
stream3366
Posts: 26
Joined: 16 Nov 2015, 17:12

Re: [HELP] Its adding an extra..

03 Oct 2023, 20:53

Thanks for the replies guys, imma try all of them now and tweak on it and then imma update this post. Thanks again
stream3366
Posts: 26
Joined: 16 Nov 2015, 17:12

Re: [HELP] Its adding an extra..

04 Oct 2023, 13:37

Sorry for double posting i cant seem to find the edit button on this new forum design.. anyways, here’s a screenschot of my desktop,
DB75C22E-B8AD-4A02-89E4-87CD46A5B269.jpeg
DB75C22E-B8AD-4A02-89E4-87CD46A5B269.jpeg (650.33 KiB) Viewed 1035 times
my screen resolution is 3840x2400 UHDR+. Unfortunately the above codes still sends extra 1.. it types in the 3 digit numbers but then somehow it erases the whole thing at once and types in the first digit by itself and continues with the script.. so basically, im just entering 1 digit number.

[Mod edit: Removed img tags which broke the attachment.]
User avatar
andymbody
Posts: 996
Joined: 02 Jul 2017, 23:47

Re: [HELP] Its adding an extra..

04 Oct 2023, 15:04

I have included comments attempting to understand what each mouse movement and click is suppose to do based on the screenshot you posted. See if it looks accurate.

Code: Select all

loop, 9
{
c := a_index
while (strlen(c) < 3) ; this can be changed to use format
	c := "0" c   ; 001, 002, 003... 009
; the following will execute with each loop iteration, but not with the while loop. 
SendInput, % c
sleep, 250
MouseMove 400, 1110 ;  move to continue button?
Sleep, 500
Click ; click continue. I suspect this is not happening?
Sleep, 100
Click ; click something on next screen? Does this happen?
sleep, 2000
MouseMove, 300, 770 ; next screen?
Sleep, 500
Click
Sleep, 500
SendInput, {Backspace 3} ; this is obviously where the backspace (erase) is coming from. Should the keypad still be visible here?
Sleep 500
}
The comments in the code are just a guess based on your description, screenshot, and numbers in the spy app. If this is incorrect please post your code with comments that describe what each movemove and click is supposed to activate (sudo code). Without that, we can only estimate by doing the math.

Also based on your stated screen resolution of 3840×2400, the size and location of the keypad window don't seem to jive to me. For instance... 2400-1728 = 672. I don't see 672 pixels below the keypad window (roughly 30% more screen). I see more like 80px below the window to bottom of Taskbar. I see a discrepancy with the width also. So something doesn't seem to add up... literally.

My suggestion would be to perform one step at a time in the loop, watching the exact location that the mouse moves to in each step. Using a sleep of like 2-3 seconds between steps. Don't do the clicks until the mouse moves to the proper spots, in the proper amount of time. Then add the clicks in one at a time, until all perform as expected. In other words, slow everything down to a crawl so the steps can be inspected one by one.

Andy
stream3366
Posts: 26
Joined: 16 Nov 2015, 17:12

Re: [HELP] Its adding an extra..

04 Oct 2023, 19:30

Close.. the first mouse move is to move it to continue button, then the first click will close the keypad then the second click clicks the continue button.. the second mouse move is to click the input field and this will show the keypad again. Will try your suggestion.. and maybe adding a loop inside the loop for the backspace would work?! Take the backspace out of the loop maybe?

Code: Select all

loop {
loop 9 {
.....
}
SendInput {BS 3}
}
like so?

Also theres no discrepancy, that window is from scrcpy and its actually the phone im trying to control through my windows pc.. the keypad pops up when you click inside the input field, but theres more to that, its just that the keypad is covering it
User avatar
andymbody
Posts: 996
Joined: 02 Jul 2017, 23:47

Re: [HELP] Its adding an extra..

06 Oct 2023, 22:41

stream3366 wrote:
04 Oct 2023, 19:30
Will try your suggestion..
Did you try this yet?
My suggestion would be to perform one step at a time in the loop, watching the exact location that the mouse moves to in each step. Using a sleep of like 2-3 seconds between steps. Don't do the clicks until the mouse moves to the proper spots, in the proper amount of time. Then add the clicks in one at a time, until all perform as expected. In other words, slow everything down to a crawl so the steps can be inspected one by one.
stream3366
Posts: 26
Joined: 16 Nov 2015, 17:12

Re: [HELP] Its adding an extra..

12 Oct 2023, 16:42

I tried everything, and it seems the backspace is effin it up.. is there any workaround for that backspace? I need to delete the 3 characters that was previously typed in before typing in the new 3 digit code and moving forward...
User avatar
andymbody
Posts: 996
Joined: 02 Jul 2017, 23:47

Re: [HELP] Its adding an extra..

12 Oct 2023, 17:04

stream3366 wrote:
12 Oct 2023, 16:42
I tried everything, and it seems the backspace is effin it up.. is there any workaround for that backspace? I need to delete the 3 characters that was previously typed in before typing in the new 3 digit code and moving forward...
If you are positive that the input box has focus at that moment, you can use Send ^a instead of the backspace.

But again, test each step one at a time, building the sequence one step at a time, until each step works as intended. This is the important part..

If you do this, it should reveal which step is causing the issue.

This may seem obvious, but I have to ask...
I assume that you are not physically touching the mouse or keyboard at any time while the script is running, correct? And no other scripts are running that may interfere?
stream3366
Posts: 26
Joined: 16 Nov 2015, 17:12

Re: [HELP] Its adding an extra..

13 Oct 2023, 20:47

Yes, i did tried doing it step by step and it is the {backspace 3}.. no im not touching anything.. will try that ctrl+a
User avatar
andymbody
Posts: 996
Joined: 02 Jul 2017, 23:47

Re: [HELP] Its adding an extra..

13 Oct 2023, 21:24

stream3366 wrote:
13 Oct 2023, 20:47
Yes, i did tried doing it step by step and it is the {backspace 3}.. no im not touching anything.. will try that ctrl+a
What does happen at the BackSpace 3 step? Does anything happen?

Is it possible that the caret is at the beginning of the text (all the way to left), rather than the end of the text (all the way to the right)? If that were the case, the backspace key shouldn't have any effect on the text in the edit box (it would remain). And would probably require moving the caret all the way to the end (right) of the text prior to using the backspace. I don't think delete would work, because you are in simulation mode, and most (if not all) phones do not have a Delete function (remove chars to the right of the current edit position).

Another possibility is... maybe the software just doesn't recognize the backspace key sent from the script, and requires the mouse to be clicked on the backspace button of the simulated on-screen keyboard instead?

Is any of this possible?
stream3366
Posts: 26
Joined: 16 Nov 2015, 17:12

Re: [HELP] Its adding an extra..

14 Oct 2023, 01:36

here's a short clip of whats happening:
gifgit.gif
gifgit.gif (244.16 KiB) Viewed 522 times
look at the .gif thats basically how its behaving..
it adds the 3 characters first and then deletes all of them and then adds 1 character which is the first character of the the 3 digit number.. if the 3 digit number starts with 3 (lets say 312) it will type in the 3 digit numbers, then deletes them and then will type 3.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 344 guests