'Send Command Not Working When A Program Gets Run In AutoHotKey

i have some code which will if the user types something, it will type that to notepad, but it is only opening notepad and not typing.

InputBox, UserInput, NoteType, Enter something to type in notepad., , 640, 480
if ErrorLevel
    ExitApp
else
    Run, Notepad
    Send, %UserInput%

Does anyone seem to have a solution for this?



Solution 1:[1]

There is a caveat when using if…else blocks in AHK, when executing multiple lines of code you have to use curly braces to enclose the block. Otherwise it just executes the first line in the block. Example:

InputBox, UserInput, NoteType, Enter something to type in notepad., , 640, 480
if ErrorLevel {
    ExitApp
} else {
    Run, Notepad
    Send, %UserInput%
}

That should work now.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 T_Lube