How to detect when something is pasted into an edit control?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
N_athan
Posts: 40
Joined: 21 Aug 2021, 16:40

How to detect when something is pasted into an edit control?

Post by N_athan » 24 Jun 2022, 10:56

Using a tool to read window messages i noted that whenever i past something in an edit control with (ctrl v) on a AutoHotkey GUI
it receives a message of wm_paste, is possible somehow to detect when this happens?

JBensimon
Posts: 118
Joined: 19 Nov 2017, 11:19

Re: How to detect when something is pasted into an edit control?

Post by JBensimon » 24 Jun 2022, 11:42

According to the documentation of the AutoHotkey OnMessage() function, it depends on whether the message is sent or posted to the control:

Code: Select all

Messages sent to a control (rather than being posted) are not monitored because
the system routes them directly to the control behind the scenes. This is seldom
an issue for system-generated messages because most of them are posted.
If the message is posted, then OnMessage() should be able to notify your code of the message arrival.

JB

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

Re: How to detect when something is pasted into an edit control?

Post by mikeyww » 25 Jun 2022, 05:16

Code: Select all

Gui, Font, s10
Gui, Add, Edit, w250
Gui, Show

#If WinActive("ahk_class AutoHotkeyGUI") && guiClassNN("Edit")
~^v::MsgBox, 64, Pasted text, %Clipboard%
#If

guiClassNN(str := "") {
 GuiControlGet, classNN, Focus
 Return str > "" ? Instr(classNN, str) : classNN
}

JBensimon
Posts: 118
Joined: 19 Nov 2017, 11:19

Re: How to detect when something is pasted into an edit control?

Post by JBensimon » 25 Jun 2022, 08:01

Good idea (and script), @mikeyww, but what if a paste occurs via Right-click + Paste?

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

Re: How to detect when something is pasted into an edit control?

Post by mikeyww » 25 Jun 2022, 08:12

Different question, different script, but I'm not sure of the script.

JBensimon
Posts: 118
Joined: 19 Nov 2017, 11:19

Re: How to detect when something is pasted into an edit control?

Post by JBensimon » 25 Jun 2022, 08:14

mikeyww wrote:
25 Jun 2022, 08:12
Different question ...
Quite right, missed that detail in the question.

Post Reply

Return to “Ask for Help (v1)”