GlobalEventsHandler.cs 920 B

12345678910111213141516171819202122232425262728
  1. using System.Windows.Forms;
  2. using UAS_PLCDataReader.Entity;
  3. namespace UAS_PLCDataReader.PublicMethod
  4. {
  5. /// <summary>
  6. /// Author zhangz 2016/12/30
  7. /// 全局事件处理,通过句柄获取触发事件的控件
  8. /// 结合捕获的全局的键盘事件来验证用户进行的操作
  9. /// </summary>
  10. class GlobalEventsHandler : IMessageFilter
  11. {
  12. //鼠标左键点击
  13. public const int WM_LBUTTONDOWN = 0x0201;
  14. //键盘敲击事件
  15. public const int WM_KEYDOWN = 0x100;
  16. public bool PreFilterMessage(ref Message m)
  17. {
  18. Control c = Control.FromHandle(m.HWnd);
  19. if (m.Msg == WM_LBUTTONDOWN && c.GetType().ToString().ToUpper().Contains("BUTTON"))
  20. {
  21. LogicHandler.DoCommandLog(User.UserCode, c.Parent.Text, "点击【" + c.Text + "】按钮");
  22. }
  23. return false;
  24. }
  25. }
  26. }