How to intercept Ctrl-V or paste command made by mouse context menu?

How to intercept Ctrl-V or paste command made by mouse context menu?

m.cicognani
Contributor Contributor
866 Views
5 Replies
Message 1 of 6

How to intercept Ctrl-V or paste command made by mouse context menu?

m.cicognani
Contributor
Contributor

Hi everybody,

I'd like to intercept the generic paste command inside AutoCAD, and it's easy with the PASTECLIP command using the BeginCommand event... but this method does not intercept the ctrl-v sequence nor the paste issued through the mouse context menu...

If I had a window I could try to override WndProc() and intercept the WM_PASTE message, but I'm inside the plugin windowless class...

Any idea?

 

Thanks,

 

Massimo

0 Likes
867 Views
5 Replies
Replies (5)
Message 2 of 6

_gile
Consultant
Consultant

Hi,

 

It seems to me CommandWillStart catches the PASTECLIP command.

 

Try this:

 

        [CommandMethod("TESTCMD")]
        public static void TestCmd()
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            doc.CommandWillStart += (_, e) =>
            {
                if (e.GlobalCommandName == "PASTECLIP")
                    Application.ShowAlertDialog(e.GlobalCommandName);
            };
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 6

m.cicognani
Contributor
Contributor

Hi Giles,
yes, indeed, but it doesn't catch the CTRL+V nor, the mouse context menu... as I wrote in the message... 😉

0 Likes
Message 4 of 6

_gile
Consultant
Consultant

Yes it does, at least from the tests I did (A2014, A2017 and A2019).

Did you try it?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 6

Anonymous
Not applicable

Yes, of course... that's exactly how I intercept the pasteclip command when issued from the ribbon, the Edit menù or typed on the command window, but that event is not fired if I press CTRL+V, although the paste operation is indeed performed... weird...  

Do you intercept the mouse context Paste command too?

0 Likes
Message 6 of 6

Anonymous
Not applicable

Ok, I made other tests and indeed the CTRL-V is translated into a PASTECLIP command, normally.
The difference in my case is that I was trying to intercept the CTRL-V when a table cell is selected. In this case the CTRL-V is translated into a TABLEDIT command, not a PASTECLIP... 

0 Likes