Page 1 of 1

Type contents of Edit box in a GUI when keybind is pressed

Posted: 27 Jan 2023, 20:39
by Nightly
I'm new to AHK v2 as it destroyed some of my AHK v1 knowledge, can someone help me with this script im trying to make?
Code should be somewhat self explanatory but eh...

Code: Select all

#Requires AutoHotkey v2.0

TyperGui := Gui("-Resize -MaximizeBox +AlwaysOnTop +Border", "Typer")
TyperGui.Add("Edit", "vTheText WantTab w235 r9", "ok")
TyperGui.Show()

^y::
{
	RealText := TyperGui.Value
	Send %RealText%
}

Re: Type contents of Edit box in a GUI when keybind is pressed

Posted: 27 Jan 2023, 21:41
by mikeyww
Welcome to this AutoHotkey forum!

Use expressions.

Code: Select all

#Requires AutoHotkey v2.0

TyperGui := Gui("-Resize -MaximizeBox +AlwaysOnTop +Border", "Typer")
ed := TyperGui.Add("Edit", "w235 r9")
TyperGui.Show

^y:: {
 TyperGui.Submit
 Sleep 50
 SendText ed.Value
}

Re: Type contents of Edit box in a GUI when keybind is pressed

Posted: 28 Jan 2023, 04:41
by just me
One line should be enough to send the text:

Code: Select all

#Requires AutoHotkey v2.0

TyperGui := Gui("-Resize -MaximizeBox +AlwaysOnTop +Border", "Typer")
TyperEdt := TyperGui.AddEdit("w235 r9", "Hello world!")
TyperGui.OnEvent("Close", TyperClose)
TyperGui.Show()

^y::SendText(TyperEdt.Value)

TyperClose(*) => ExitApp()

Re: Type contents of Edit box in a GUI when keybind is pressed

Posted: 28 Jan 2023, 05:46
by mikeyww
Well, over here, the GUI has to be hidden first!

Re: Type contents of Edit box in a GUI when keybind is pressed

Posted: 29 Jan 2023, 05:42
by just me
@mikeyww, it's not necessary to hide the GUI. It's sufficient to activate the target window before you press the hotkey. Hiding the GUI might activate a 'wrong' window.

Re: Type contents of Edit box in a GUI when keybind is pressed

Posted: 29 Jan 2023, 06:04
by mikeyww
I see what you mean. Either approach could work, depending on the need. Thanks.