ControlSend randomly switches between upper and lower case

Report problems with documented functionality
nepdev
Posts: 8
Joined: 04 Jun 2018, 10:13

ControlSend randomly switches between upper and lower case

Post by nepdev » 17 Mar 2021, 02:27

When sending text strings to a legacy MS DOS window under Windows XP with ControlSend, the text appears with mixed lower and upper case letters even though the actual text string is all upper case.
Example command

ControlSend ,, TEST-TEXT, ahk_id %myWindowID%

Occasionally it does it right and then sometimes it is completely garbled. There is no telling which one of the letters will become lower case.
Running the script 5 times results in 5 different text arriving to the window. This is especially annoying when the text contains symbols or numbers which then turn in to other symbols due to Shift+key being different than "key".
I also noticed that it omits characters at times.

I have to use ControlSend as this is the only thing I found working on a VM over a remote desktop session, even if the window is minimized.
But it does not even work any better if directly logged in without RDP.

What I tried

So I increased SetKeyDelay up to 200 with no difference at all.
I made a loop which splits the text into single characters and it sends it character by character.
This changes nothing, the result is the same.

As mentioned, sometimes it works just perfectly, sometimes it only changes one letter, sometimes half of them are changed to lower case, sometimes even all of them.

This is extremely unreliable, but I cannot find much mention of this around on the internet - any idea?

gregster
Posts: 8921
Joined: 30 Sep 2013, 06:48

Re: ControlSend randomly switches between upper and lower case

Post by gregster » 17 Mar 2021, 02:35

Try to add {text} mode (requires AHK v1.1.27+):

Code: Select all

ControlSend ,, {text}TEST-TEXT, ahk_id %myWindowID%

nepdev
Posts: 8
Joined: 04 Jun 2018, 10:13

Re: ControlSend randomly switches between upper and lower case

Post by nepdev » 17 Mar 2021, 03:08

Hm - I am using 1.1.33 but it does nothing, or actually less than nothing - as soon as I put {text} in front of my string, it sends nothing at all any more - an empty string. Don't see any syntax changes in my AHK help file for 1.1.33.

nepdev
Posts: 8
Joined: 04 Jun 2018, 10:13

Re: ControlSend randomly switches between upper and lower case

Post by nepdev » 17 Mar 2021, 03:10

Also with variables it does not do anything, still sends an empty string:

ControlSend ,, {text}%fieldname%, ahk_id %myWindowID%

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: ControlSend randomly switches between upper and lower case

Post by boiler » 18 Mar 2021, 10:35

Just to eliminate all other possible issues, I suggest confirming the following works from your script when you have a Notepad window open:

Code: Select all

ControlSend ,, {text}TEST-TEXT, ahk_exe Notepad.exe

nepdev
Posts: 8
Joined: 04 Jun 2018, 10:13

Re: ControlSend randomly switches between upper and lower case

Post by nepdev » 18 Mar 2021, 12:51

Checked that - works properly to send to Notepad window.
I tried also with ahk_id instead of ahk_exe, just in case - still works.

But going back to my legacy application - there it works (with garbled letters) if no {text} is prepended,
and does not work (sends no text at all) if we have {text}.

Manually typing as a user has zero issues in that legacy app. Also did not really notice this issue before,
but that specific form I need to enter data in makes this problem happen every time. It is a MS DOS
app from many years ago. Curiously really no problem typing into it via keyboard, never.

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: ControlSend randomly switches between upper and lower case

Post by boiler » 18 Mar 2021, 13:34

Another thing to try:

Code: Select all

Clipboard := "TEST-TEXT"
WinActivate, ahk_id %myWindowID% ; define myWindowID earlier, of course
Send, ^v

nepdev
Posts: 8
Joined: 04 Jun 2018, 10:13

Re: ControlSend randomly switches between upper and lower case

Post by nepdev » 18 Mar 2021, 15:29

With the clipboard it works to a Notepad window.
No garbles, but I do not seem to get any garbles to Notepad in any way I try.

What would this indicate?

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: ControlSend randomly switches between upper and lower case

Post by boiler » 18 Mar 2021, 15:31

I was interested in knowing if the clipboard approach worked with your other window, not Notepad. Is it still garbled when you paste to that window from the clipboard? If not, then you can use that approach in general instead of Send or ControlSend.

nepdev
Posts: 8
Joined: 04 Jun 2018, 10:13

Re: ControlSend randomly switches between upper and lower case

Post by nepdev » 18 Mar 2021, 16:24

No, that does not work. It does not understand Windows cut and paste commands, it's a DOS app.

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: ControlSend randomly switches between upper and lower case

Post by boiler » 18 Mar 2021, 17:09

Such apps sometimes allow copy and paste via the Windows clipboard when the options are set to allow it. For example, the CMD window allows it with its “QuickEdit” mode, which is set by clicking the icon in title bar and selecting “Properties” or “Defaults”. If you are not using the CMD window, is it on option for running your DOS app?

By the way, I am able to use ControlSend to send TEST-TEXT to the CMD window without it being garbled, so the paste approach may not be required if you are able to use it.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: ControlSend randomly switches between upper and lower case

Post by swagfag » 18 Mar 2021, 18:26

https://www.autohotkey.com/docs/commands/ControlSend.htm#Remarks
do what the remarks say for Alt, but with Shift instead

nepdev
Posts: 8
Joined: 04 Jun 2018, 10:13

Re: ControlSend randomly switches between upper and lower case

Post by nepdev » 21 Mar 2021, 16:00

@swagfag - thank you very much: this was pointing me in the right direction.

I believe you were trying to say to use {Shift down} and {Shift up} but I had tried that already earlier and did not change.
But the same page speaks about edit/paste commands, and this works. As it's a DOS window I had to use:

WinMenuSelectItem ahk_id %windowID%,, 0&, Edit, Paste

Thanks to @boiler - yes, the clipboard approach in the end did work!
One reason why this was so difficult may be the fact that this legacy app is not merely MS DOS but a 16-bit app running under NTVDM, so that's an extra layer of virtualization everything has to pass through ...

And many thanks to everyone who helped, I appreciate the assistance!

User avatar
eagleDog
Posts: 11
Joined: 28 Aug 2023, 01:00
Contact:

Re: ControlSend randomly switches between upper and lower case

Post by eagleDog » 25 Sep 2023, 21:34

Thanks nepdev. Your Edit, Paste solution worked for me.
Here is the code I ended up using:

Code: Select all

WinMenuSelectItem ahk_exe cmd.exe,, 0&, Edit, Paste
I was having troubles with this simple line of code:

Code: Select all

ControlSend, , P1P3P1R1, ahk_exe cmd.exe
It should just send P1P3P1R1 to the console, but
instead it shows up as P1p#p!r1, basically garbledy goop.

Specifically the problem for me occurs with numbers between
uppercase capital letters, and not for the same patterns with
lowercase letter. Btw, I am trying to parse Chess positions with
FEN notation, hence the need to send this type of string to the
console.

Thanks again. Best regards!

Post Reply

Return to “Bug Reports”