Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trigger to respond to clipboard changes
#2
Click menu TT -> Other triggers.
Insert this text near the end, before the last }.
Click Run.
 
Code:
Copy      Help
    [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);
    }


Messages In This Thread
RE: Trigger to respond to clipboard changes - by Gintaras - 12-28-2023, 12:26 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)