ControlSend, issues regarding special characters and reliability Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
JeMykle
Posts: 6
Joined: 04 Sep 2020, 03:33

ControlSend, issues regarding special characters and reliability

Post by JeMykle » 24 Jan 2021, 12:10

Does anyone know how to imrpove reliability of ControlSend? I am in particular having issues with @, guessing any special character as well, really. If there are any alternatives to sending to a unfocused window, rather than ControlSend, I would gladely change my approach.

Code: Select all

SendMode Play
SetKeyDelay, -1, -1, Play

windowTitle := "Some unfocused window"
WinGet, win_pid, PID, %windowTitle%
ControlFocus, , ahk_pid %win_pid%
Text := StrSplit("@[email protected]@[email protected]@[email protected]")
specialChars := StrSplit("!#$%&'()*+,-/:;<=>[email protected][\]^_`{|}~£€´¨Øµ÷׿»«§¦¥¢¡")
Sleep 300
outer:
    for k, char in Text {
        for l, special in specialChars {
            if (char == special){
                ControlSendRaw, , %special%, ahk_pid %win_pid%
                Sleep 300
                continue_outer:
            }
        }
        ControlSend,  ,{%char% Down}, ahk_pid %win_pid%
        Sleep 300
        ControlSend, ,{%char% Up}, ahk_pid %win_pid%
        Sleep 300
    }

Tried this thing with ControlSendRaw, ControlSendRaw seems equally consistent/bad compared to the regular ControlSend.
I have done some testing with KeyHistory and ToolTip:

Code: Select all

^2::KeyHistory
#InstallKeybdHook
#KeyHistory 200

;When trying to ControlSend "@@@@" this returns:

;----------------------------------------------------------------
A5  138    i    u    0.02    RAlt
A5  138    i    d    0.19    RAlt
A5  138    i    u    0.02    RAlt
A5  138    i    d    0.23    RAlt
A5  138    i    u    0.02    RAlt
A5  138    i    d    0.28    RAlt
A5  138    i    u    0.02    RAlt
A5  138    i    d    0.17    RAlt

;When I am writing on my keyboard it picks up everything like it should. I think KeyHistory works as intended for that, maybe it doesn't do what it should for ControlSend? 

;-----------------------------------------------------------------
;Have also tried ToolTipping to see last key, didn't gain any valuable knowledge from that either.
loop{
	ToolTip, %a_priorkey%
	Sleep 100	
}
gregster
Posts: 6028
Joined: 30 Sep 2013, 06:48

Re: ControlSend, issues regarding special characters and reliability  Topic is solved

Post by gregster » 24 Jan 2021, 12:23

You could @lso try {text} mode (requires AHK v1.1.27+) with ControlSend (usually, I have better results with it than with raw mode):

Code: Select all

ControlSend, , {text}%char%, ahk_pid %win_pid%
I think, down and up events don't apply to this send mode, though.
JeMykle
Posts: 6
Joined: 04 Sep 2020, 03:33

Re: ControlSend, issues regarding special characters and reliability

Post by JeMykle » 24 Jan 2021, 12:58

gregster wrote:
24 Jan 2021, 12:23
You could @lso try {text} mode (requires AHK v1.1.27+) with ControlSend (usually, I have better results with it than with raw mode):

Code: Select all

ControlSend, , {text}%char%, ahk_pid %win_pid%
I think, down and up events don't apply to this send mode, though.
I'll try that! Insight into if down and up events apply would be useful.
gregster
Posts: 6028
Joined: 30 Sep 2013, 06:48

Re: ControlSend, issues regarding special characters and reliability

Post by gregster » 24 Jan 2021, 13:27

JeMykle wrote:
24 Jan 2021, 12:58
Insight into if down and up events apply would be useful.
in my understanding, {text} mode does not translate a character to single key events, but actually sends a character instead (with a different Windows API function than the default; ControlSend uses then WM_CHAR internally, iirc; for this method, keypress duration should be irrelevant). But this is what I understand from the AHK docs, I haven't checked in the AHK source code.

Others might be able to correct me or to add to this.
Post Reply

Return to “Ask For Help”