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

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Nightly
Posts: 1
Joined: 27 Jan 2023, 20:37

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

Post by Nightly » 27 Jan 2023, 20:39

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%
}

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

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

Post by mikeyww » 27 Jan 2023, 21:41

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
}

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

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

Post by just me » 28 Jan 2023, 04:41

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()

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

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

Post by mikeyww » 28 Jan 2023, 05:46

Well, over here, the GUI has to be hidden first!

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

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

Post by just me » 29 Jan 2023, 05:42

@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.

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

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

Post by mikeyww » 29 Jan 2023, 06:04

I see what you mean. Either approach could work, depending on the need. Thanks.

Post Reply

Return to “Ask for Help (v2)”