using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.Runtime; [assembly:CommandClass(typeof(TestRunCommand.Class1))] namespace TestRunCommand { public class Class1 { const int WM_RBUTTONDOWN = 516; [CommandMethod("TestRunCommand")] public void TestRunCommand() { Application.PreTranslateMessage += new PreTranslateMessageEventHandler(Application_PreTranslateMessage); } private void Application_PreTranslateMessage(object sender, PreTranslateMessageEventArgs e) { if(e.Message.message==WM_RBUTTONDOWN) { System.Windows.Forms.MessageBox.Show("你点击了鼠标右键"); } } [CommandMethod("TestOff")] public void TestOff() { Application.PreTranslateMessage -= new PreTranslateMessageEventHandler(Application_PreTranslateMessage); } } }
下面给出一些鼠标事件的16进制值(程序里用到的是10进制),用的时候自己转一下10进制:
WM_MOUSEFIRST 0x0200
WM_MOUSEMOVE 0x0200
WM_LBUTTONDOWN 0x0201
WM_LBUTTONUP 0x0202
WM_LBUTTONDBLCLK 0x0203
WM_RBUTTONDOWN 0x0204
WM_RBUTTONUP 0x0205
WM_RBUTTONDBLCLK 0x0206
WM_MBUTTONDOWN 0x0207
WM_MBUTTONUP 0x0208
WM_MBUTTONDBLCLK 0x0209
(原文地址:http://bbs.mjtd.com/thread-79667-1-1.html)
适用AutoCAD2009及以上版本,注意添加WindowsBase引用
时间: 2024-10-10 17:21:24