TheSwamp

Code Red => .NET => Topic started by: kh001058 on November 28, 2019, 09:19:15 AM

Title: How to catch mouse click events.
Post by: kh001058 on November 28, 2019, 09:19:15 AM
Hi everybody,

I'm trying to mimic the PAN command, to begin, it must be catch the mouse click events, I think.
Is there anyway to detect the mouse click event in AutoCAD.NET : mouse_down, mouse_move, mouse_up ...

Any help regarding this issue will be appreciated.
Regards.
Title: Re: How to catch mouse click events.
Post by: Jeff H on December 03, 2019, 01:41:25 AM
I had to monitor mouse events inside of Editor.CommandAsync/Editor.Command and used Autodesk.AutoCAD.ApplicationServices.Core.Application.PreTranslateMessage Event

Code - C#: [Select]
  1.         private const int MK_SHIFT = 4;
  2.         private const int WM_RBUTTONUP = 517;
  3.         private const int WM_LBUTTONUP = 514;
  4.         private const int WM_LBUTTONDOWN = 513;
  5.         private const int WM_RBUTTONDOWN = 516;
  6.  
  7.         private void Application_PreTranslateMessage(object sender, PreTranslateMessageEventArgs e)
  8.         {          
  9.             var wp = e.Message.wParam.ToInt64();
  10.  
  11.             if (e.Message.message == WM_RBUTTONDOWN && (wp != 6 && wp != MK_SHIFT))
  12.             {
  13.                 e.Handled = true;
  14.             }
  15.             if (e.Message.message == WM_RBUTTONUP && wp != MK_SHIFT)
  16.             {
  17.                 Application.PreTranslateMessage -= Application_PreTranslateMessage;
  18.                 e.Handled = true;
  19.                 Application.DocumentManager.MdiActiveDocument.SendCancel();
  20.             }
  21.         }
  22.  

Not much info in acad docs so this might help
https://docs.microsoft.com/en-us/windows/win32/learnwin32/mouse-clicks (https://docs.microsoft.com/en-us/windows/win32/learnwin32/mouse-clicks)
https://docs.microsoft.com/en-us/windows/win32/inputdev/mouse-input-notifications (https://docs.microsoft.com/en-us/windows/win32/inputdev/mouse-input-notifications)