ControlSend and shift Topic is solved

Ask gaming related questions
handerson
Posts: 3
Joined: 12 Jan 2024, 05:38

ControlSend and shift

12 Jan 2024, 05:53

Hello, I have script that uses ControlSend to send keystrokes to a background window, which works just fine. However, the problem is, when I type something in a different window, and press down the shift key , the ControlSend inputs react the hold down shift key and send the key input in lowercase/uppercase . This does not really matter for me, as the window ControlSend is acting on is not case sensetive, but my text that was I was typing in the active windows is also affected by that, because the ControlSend command "snatches" the hold down shift key input. To put it an a different way: I would like to type in an active window, without ControlSend messing with the shift key.


Do you have any idea how to avoid this behaviour? Blockinput is not an option, because I send the ControlSend commands with small delays.

Here some minimal example, F5 starts and F4 stops the script.

Code: Select all

F5:: {
Global on := True
While on {
Loop 10
{
ControlSend("{f}",, "window name")
sleep 100
}
}}

F4:: {
 Global on := False
}

User avatar
mikeyww
Posts: 27216
Joined: 09 Sep 2014, 18:38

Re: ControlSend and shift

12 Jan 2024, 08:49

Welcome to this AutoHotkey forum!

That sounds tricky. You can always use AHK to send a modifier key up, but there is no guarantee that it will work properly, especially if you are typing at the same time. You can try it.

It isn't really magic. The bottom line is that if you and AHK are sending text at the same time, your actions may conflict with each other.

Explained: Send
handerson
Posts: 3
Joined: 12 Jan 2024, 05:38

Re: ControlSend and shift

12 Jan 2024, 09:13

Thanks, so this is a tricky problem that is not easy to solve?

The best way would be to ControlSend input without any interference with the user input. But i have also thought about something like checking before each ControlSend command, if the shift key is pressed and if it is, then to send the key input + holding down the shift key. Because then, windows might recognize it as still shift still beeing presse, when i type in the active window. But im not sure if that makes sense.


Another idea would be write a second script that automatically sends for example a small letter when I press a trigger key+ a letter. So basically avoiding the shift key. If i press a trigger key + the "A" key -> the script sends an capital "A" as input.

Do you think this might work? I guess i will wait for now and see if maybe someone has an elegant way of solving this problem ^^"
User avatar
mikeyww
Posts: 27216
Joined: 09 Sep 2014, 18:38

Re: ControlSend and shift

12 Jan 2024, 09:43

Worth a try. Experimentation is sometimes the fastest way to an answer.
User avatar
Noitalommi_2
Posts: 287
Joined: 16 Aug 2023, 10:58

Re: ControlSend and shift  Topic is solved

12 Jan 2024, 09:50

Hi.

I couldn't get it to work with ControlSend either but PostMessage doesn't seem to interfere(?) but will send uppercase letters while holding Shift.
I only tested it with Notepad, maybe it will work with your game.

Code: Select all

#Requires AutoHotkey >=2.0
#SingleInstance

; F5 start
; F4 stop

Key := "f"

WinTitle := "MyWinTitle"
Control := ""

/* just for testing
WinTitle := "ahk_exe Notepad.exe"
Control := "RichEditD2DPT1"
*/

VK := GetKeyVK(Key)
SC := GetKeySC(Key)

F5::{

	Loop {
		
		PostMessage(0x0100, VK, 0 | SC << 16, Control, WinTitle) ;WM_KEYDOWN
		Sleep 100
		PostMessage(0x0101 , VK, 0 | SC << 16 | 1 << 30 | 1 << 31, Control, WinTitle) ; WM_KEYUP
	}until GetKeyState("F4")
}
handerson
Posts: 3
Joined: 12 Jan 2024, 05:38

Re: ControlSend and shift

12 Jan 2024, 10:45

Hello Noitalommi_2, I have tried your script, and after removing the control commands, it looks like it is able to send the keyinput without messing with the shift key. I will have to look up all the commands that you have used to understand how it works in more detail and then apply it to my actual script. Thank you very much!

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 2 guests