Posts: 53
Threads: 21
Joined: Jul 2021
QuickMacro has a trigger "Clipboard copy" - I would like to write code in LA that responds to clipboard changes. How can that be done?
I checked "Other Triggers", found the pointers to WinEventHook.WinEventHook - but I can't find anything related to clipboard changes in the list of
Event Constants - so maybe it uses a different mechanism. I'm afraid I don't know these mechanisms well enough - so would appreciate some help
Posts: 12,061
Threads: 140
Joined: Dec 2002
12-28-2023, 12:26 PM
(This post was last modified: 12-28-2023, 12:30 PM by Gintaras.)
Click menu TT -> Other triggers.
Insert this text near the end, before the last }.
Click Run.
[Triggers]
void ClipboardTriggers() {
var w1 = WndUtil.CreateMessageOnlyWindow(static nint (wnd w, int msg, nint wp, nint lp) => {
if (msg == api.WM_CLIPBOARDUPDATE) {
print.it("Clipboard trigger");
//if want to get clipboard text, do it with a delay, else it may interfere with other clipboard programs or scripts
timer.after(100, _ => {
var s = clipboard.text;
print.it(s);
});
}
return api.DefWindowProc(w, msg, wp, lp);
}, "#32770");
api.AddClipboardFormatListener(w1);
}
unsafe class api : NativeApi {
[DllImport("user32.dll", EntryPoint = "DefWindowProcW")]
internal static extern nint DefWindowProc(wnd hWnd, int msg, nint wParam, nint lParam);
internal const int WM_CLIPBOARDUPDATE = 0x31D;
[DllImport("user32.dll")]
internal static extern bool AddClipboardFormatListener(wnd hwnd);
}
Posts: 53
Threads: 21
Joined: Jul 2021
Thank you - that's exactly what I needed!