Author Topic: How to catch mouse click events.  (Read 200 times)

0 Members and 1 Guest are viewing this topic.

kh001058

  • Mosquito
  • Posts: 5
How to catch mouse click events.
« 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.

Jeff H

  • Needs a day job
  • Posts: 6050
Re: How to catch mouse click events.
« Reply #1 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/inputdev/mouse-input-notifications
« Last Edit: December 03, 2019, 01:47:34 AM by Jeff H »