public override string ToString() { return(MouseEventType.ToString()); }
//Cambiar a static para evitar que al GC se le vaya la olla y me lo borre private static IntPtr hookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (instance == null) { return((IntPtr)1); } bool result = true; if (nCode >= 0 && instance.childProcedure != null) { if (instance.manejadorEventos != null) { MOUSEINPUT hookStruct = new MOUSEINPUT(); int param = wParam.ToInt32(); MouseEventType tipoEvento = Enum.IsDefined(typeof(MouseEventType), param) ? (MouseEventType)Enum.ToObject(typeof(MouseEventType), param) : MouseEventType.NONE; if (!tipoEvento.Equals(MouseEventType.NONE)) { hookStruct = (MOUSEINPUT)Marshal.PtrToStructure(lParam, typeof(MOUSEINPUT)); //Recuperamos el valor guardado en la dirección de memoria especificada Debug.WriteLineIf(instance.stopPropagation, "Se ha interceptado un vento de tipo " + tipoEvento.ToString() + " con data { MouseData = " + hookStruct.mouseData + " , ExtraInfo = " + hookStruct.dwExtraInfo + ", Time = " + hookStruct.time + " , Flags = " + hookStruct.dwFlags + "} "); switch (tipoEvento) { case MouseEventType.WM_MOUSEMOVE: instance.currentPos = new POINT(hookStruct.dx, hookStruct.dy); result = instance.manejadorEventos.onMouseMove(instance, hookStruct); if (instance.stopPropagation == true && hookStruct.dwExtraInfo.ToInt32() != -1) //Se esta ejecutando moveToPointHumanized y no se trata de un evento enviado por el mismo { result = false; } break; case MouseEventType.WM_LBUTTONDOWN: result = instance.manejadorEventos.onLeftMouseButtonDown(instance, hookStruct); break; case MouseEventType.WM_LBUTTONUP: result = instance.manejadorEventos.onLeftMouseButtonUp(instance, hookStruct); break; case MouseEventType.WM_MBUTTONDOWN: result = instance.manejadorEventos.onMiddleMouseButtonDown(instance, hookStruct); break; case MouseEventType.WM_MBUTTONUP: result = instance.manejadorEventos.onMiddleMouseButtonUp(instance, hookStruct); break; case MouseEventType.WM_RBUTTONDOWN: result = instance.manejadorEventos.onRightMouseButtonDown(instance, hookStruct); break; case MouseEventType.WM_RBUTTONUP: result = instance.manejadorEventos.onRightMouseButtonUp(instance, hookStruct); break; case MouseEventType.WM_MOUSEWHEEL: result = instance.manejadorEventos.onVerticalWheelMouseRotation(instance, hookStruct); break; case MouseEventType.WM_MOUSEHWHEEL: result = instance.manejadorEventos.onHorizontalWheelMouseRotation(instance, hookStruct); break; } } } } if (result) { return(CallNextHookEx(instance.getHookID(), nCode, wParam, lParam)); //Permite seguir propagando el evento a otras aplicaciones } else { return((IntPtr)1); //Bloquea la propagación del evento a otras aplicaciones } }