ControlSend makes keys like Ctrl/Shift not function correctly

Report problems with documented functionality
DontHurtMe
Posts: 6
Joined: 10 Jul 2017, 16:25

ControlSend makes keys like Ctrl/Shift not function correctly

12 Jul 2017, 12:45

Code: http://p.ahkscript.org/?p=2707aa8a

Code: Select all

http://p.ahkscript.org/?p=2707aa8a
For example, this is a simple script that the problem occurs in. Replace the 'example.exe' part with any other program. This problem occurs in all programs (tested on three different problems) and also probably with all keys (tried on arrow keys down/up and normal letters down/up).

The problem makes keys like Ctrl and Shift behave weirdly in other programs while the keypresses are done in the background.
If you cannot run the script yourself, I will show you what the problem looks like. On the next row, I will start typing the word 'Shift' over and over again, at the start of every word I will hold down shift and at the end of the word I will release it and re-press it. This is done while the script and loop is running:
SHift SHIft shift shift Shift Shift Shift shift shift Shift Shift SHift SHift SHIft shift shift SHift shift shift Shift SHift SHift SHIft Shift shift SHift

As you can see sometimes it never registers the shift press, sometimes just stops half-way even though I am still holding it down. The weird key behavior happens while typing both IN the window that the script is sending keypresses and also in other windows.

I also know that this problem is not occurring only to me as I shared this script with someone else and he had the same problem. I am running 64-bit Windows 7, even though that probably doesn't matter.
lexikos
Posts: 6653
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: ControlSend makes keys like Ctrl/Shift not function correctly

12 Jul 2017, 21:41

This is not a bug. ControlSend is functioning as intended.
By default, modifier keystrokes (Control, Alt, Shift, and Win) are sent as they normally would be by the Send command. This allows command prompt and other console windows to properly detect uppercase letters, control characters, etc. It may also improve reliability in other ways.

However, in some cases these modifier events may interfere with the active window, especially if the user is actively typing during a ControlSend or if the Alt key is being sent (since Alt activates the active window's menu bar). This can be avoided by explicitly sending modifier up and down events as in this example:

Code: Select all

ControlSend, Edit1, {Alt down}f{Alt up}, Untitled - Notepad
vlayon
Posts: 1
Joined: 19 Sep 2019, 04:29

Re: ControlSend makes keys like Ctrl/Shift not function correctly

19 Sep 2019, 04:46

Hello there,
I am using AutoIt with Java (autoitx4java library).
I am observing the behavior with unnecessary clicked "Shift" buton too.
What I was trying is to upload a document in Internet Explorer.

For example:
I am sending with ControlSend this text : "C:\Users\Public\Documents\29_PotsRetention_13518044_20190919120738-33673186.pdf", and the result is like : "C;\Users\Public\Documents\29_PotsRetention_13518044_20190919120738-33673186.pdf", or "C:\Users|Public\Documents\29_PotsRetention_13518044_20190919120738-33673186.pdf".

When I send with ControlSend "{Blind}C:\Users\Public\Documents\29_PotsRetention_13518044_20190919120738-33673186.pdf", the result is "BC:\Users\Public\Documents\29_PotsRetention_13518044_20190919120738-33673186.pdf".
Why ControlSend is sending this "B" when I use {Blind}?

This is my code:
"
autoIt.winWait("Choose File to Upload");
autoIt.controlSend("Choose File to Upload", "", "Edit1", "{Blind}" + fullPath);

"
Screenshot is attached
Attachments
AutoIt_ControlSend_Blind.jpg
AutoIt_ControlSend_Blind.jpg (80.32 KiB) Viewed 438 times
swagfag
Posts: 3003
Joined: 11 Jan 2017, 17:59

Re: ControlSend makes keys like Ctrl/Shift not function correctly

19 Sep 2019, 05:15

what does autoit have to do with autohotkey?
besides, i doubt its even got the blind modifier implemented
SOTE
Posts: 791
Joined: 15 Jun 2015, 06:21

Re: ControlSend makes keys like Ctrl/Shift not function correctly

20 Sep 2019, 08:43

DontHurtMe wrote:
12 Jul 2017, 12:45
Code: http://p.ahkscript.org/?p=2707aa8a

Code: Select all

http://p.ahkscript.org/?p=2707aa8a
For example, this is a simple script that the problem occurs in. Replace the 'example.exe' part with any other program. This problem occurs in all programs (tested on three different problems) and also probably with all keys (tried on arrow keys down/up and normal letters down/up).

The problem makes keys like Ctrl and Shift behave weirdly in other programs while the keypresses are done in the background.
If you cannot run the script yourself, I will show you what the problem looks like. On the next row, I will start typing the word 'Shift' over and over again, at the start of every word I will hold down shift and at the end of the word I will release it and re-press it. This is done while the script and loop is running:
SHift SHIft shift shift Shift Shift Shift shift shift Shift Shift SHift SHift SHIft shift shift SHift shift shift Shift SHift SHift SHIft Shift shift SHift

As you can see sometimes it never registers the shift press, sometimes just stops half-way even though I am still holding it down. The weird key behavior happens while typing both IN the window that the script is sending keypresses and also in other windows.
You might want to check out and experiment with BlockInput (https://www.autohotkey.com/docs/commands/BlockInput.htm). If you or a user is actively using the keyboard while at the same time an AutoHotkey program is trying to send keys, then this can avoid the inputs from interfering with each other.

Note- Make sure to always us BlockInput Off, if you have used BlockInput On, so to not freeze your keyboard by mistake.

You can also try SendInput (https://www.autohotkey.com/docs/commands/Send.htm#SendInputDetail).

SendInput and SendPlay [v1.0.43+]: SendInput and SendPlay use the same syntax as Send but are generally faster and more reliable. In addition, they buffer any physical keyboard or mouse activity during the send, which prevents the user's keystrokes from being interspersed with those being sent.
Last edited by SOTE on 20 Sep 2019, 09:00, edited 2 times in total.
SOTE
Posts: 791
Joined: 15 Jun 2015, 06:21

Re: ControlSend makes keys like Ctrl/Shift not function correctly

20 Sep 2019, 08:48

vlayon wrote:
19 Sep 2019, 04:46
Hello there,
I am using AutoIt with Java (autoitx4java library).
I am observing the behavior with unnecessary clicked "Shift" buton too.
What I was trying is to upload a document in Internet Explorer.
AutoHotkey and AutoIt are 2 different scripting languages and this is clearly not the AutoIt Forums. You should take that question to the AutoIt Forum. Also your example is not helping the OP either, since you are referencing a different scripting language.

Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 4 guests