// Init Mouse Control private void InitGlobalMouseHook() { mouseHook = new GlogbleMouseHook(); mouseHook.OnMouseActivity += new GlogbleMouseHook.MouseActiveHandler(mouseHook_OnMouseActivity); }
private bool mouseHook_OnMouseActivity(object sender, GlogbleMouseHook.MouseMessage wMsg, GlogbleMouseHook.MouseHookStruct lMsg) { switch (wMsg) { case GlogbleMouseHook.MouseMessage.RDown: if (release) release = false; else { release = true; return false; } showTrace = true; mouseStroke = "@"; lastStoke = string.Empty; ptStart = ptAnchor = lMsg.Point; return true; case GlogbleMouseHook.MouseMessage.Move: if (showTrace) { int dx = lMsg.Point.X - ptAnchor.X; int dy = lMsg.Point.Y - ptAnchor.Y; if (dx * dx + dy * dy > ditherThreshold * ditherThreshold) { if (isAeroEffectOn) { // Prevent the command from affecting the canvas window. if (strokeCanvas.IsDisposed || strokeCanvas == null) { strokeCanvas = new StrokeCanvas(); strokeCanvas.Show(); gStroke = strokeCanvas.CreateGraphics(); } if (!strokeCanvas.Visible) { ys.Common.ShowWindow(strokeCanvas.Handle, Common.WindowState.SW_SHOWNA); if (strokeCanvas.WindowState != System.Windows.Forms.FormWindowState.Maximized) strokeCanvas.WindowState = System.Windows.Forms.FormWindowState.Maximized; } } gStroke.DrawLine(penStroke, ptAnchor.X, ptAnchor.Y, lMsg.Point.X, lMsg.Point.Y); ptAnchor = lMsg.Point; string stroke = string.Empty; if (dx > Math.Abs(dy) && dx > 0) stroke += ">"; else if (Math.Abs(dx) > Math.Abs(dy) && dx < 0) stroke += "<"; else if (dy > Math.Abs(dx) && dy > 0) stroke += "v"; else if (Math.Abs(dy) > Math.Abs(dx) && dy < 0) stroke += "^"; if (stroke != lastStoke) mouseStroke += stroke; lastStoke = stroke; } } return false; case GlogbleMouseHook.MouseMessage.RUp: if (!release) { showTrace = false; // If mouse move little, invoke the default mosue event. if (Math.Pow(lMsg.Point.X - ptStart.X, 2) + Math.Pow(lMsg.Point.Y - ptStart.Y, 2) <= ditherThreshold * ditherThreshold) { ys.StrokeParser.SendStrokes("MR"); } else { release = true; if (isAeroEffectOn) { // Clear the stroke on screen strokeCanvas.Refresh(); strokeCanvas.Visible = false; } else { ys.Common.InvalidateRect(IntPtr.Zero, IntPtr.Zero, true); } LaunchArrows(); } return true; } else return false; default: return false; } }