void OnMouseGrabEnterPart(Part part)
        {
            if (!grabActive)
            {
                return;
            }
            grabOk = false;
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            if (KISAddonPointer.isRunning)
            {
                return;
            }
            if (hoverInventoryGui())
            {
                return;
            }
            if (draggedPart == part)
            {
                return;
            }
            ModuleKISPartDrag  pDrag       = part.GetComponent <ModuleKISPartDrag>();
            ModuleKISPartMount parentMount = null;

            if (part.parent)
            {
                parentMount = part.parent.GetComponent <ModuleKISPartMount>();
            }
            ModuleKISItem item = part.GetComponent <ModuleKISItem>();

            // Drag part over another one if possible (ex : mount)
            if (draggedPart && pDrag)
            {
                KISAddonCursor.CursorEnable(pDrag.dragIconPath, pDrag.dragText, '(' + pDrag.dragText2 + ')');
                return;
            }

            if (draggedPart)
            {
                KISAddonCursor.CursorDisable();
                return;
            }

            // Do nothing if part is EVA
            if (part.vessel.isEVA)
            {
                return;
            }

            // Check part distance
            if (!HasActivePickupInRange(part))
            {
                KISAddonCursor.CursorEnable("KIS/Textures/tooFar", "Too far", "(Move closer to the part)");
                return;
            }

            // Check part mass
            float pMass         = (part.mass + part.GetResourceMass());
            float pickupMaxMass = GetAllPickupMaxMassInRange(part);

            if (pMass > pickupMaxMass)
            {
                KISAddonCursor.CursorEnable("KIS/Textures/tooHeavy", "Too heavy", "(Bring more kerbal [" + pMass + " > " + pickupMaxMass + ")");
                return;
            }

            // Check if part can be detached and grabbed
            if (!parentMount)
            {
                if (part.children.Count > 0 || part.parent)
                {
                    //Part with a child or a parent
                    if (item)
                    {
                        if (item.allowPartAttach == 0)
                        {
                            KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Can't grab", "(This part can't be detached)");
                            return;
                        }
                        else if (item.allowPartAttach == 2)
                        {
                            ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true);
                            if (!pickupModule)
                            {
                                if (FlightGlobals.ActiveVessel.isEVA)
                                {
                                    KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(This part can't be detached without a tool)");
                                    return;
                                }
                                else
                                {
                                    KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach function is not supported on this part)");
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true);
                        if (!pickupModule)
                        {
                            if (FlightGlobals.ActiveVessel.isEVA)
                            {
                                KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(This part can't be detached without a tool)");
                                return;
                            }
                            else
                            {
                                KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach function is not supported on this part)");
                                return;
                            }
                        }
                    }
                }
                else
                {
                    // Part without childs and parent
                    if (item)
                    {
                        if (item.staticAttached && item.allowStaticAttach == 2)
                        {
                            ModuleKISPickup pickupModule = GetActivePickupNearest(part, canStaticAttachOnly: true);
                            if (!pickupModule)
                            {
                                if (FlightGlobals.ActiveVessel.isEVA)
                                {
                                    KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(This part can't be detached from the ground without a tool)");
                                    return;
                                }
                                else
                                {
                                    KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach from ground function is not supported on this part)");
                                    return;
                                }
                            }
                        }
                    }
                }
            }

            // check number of part attached
            if (part.parent)
            {
                if (part.children.Count > 0)
                {
                    KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Can't grab", "(" + (part.children.Count + 1) + " parts is attached to it)");
                    return;
                }
            }
            else
            {
                if (part.children.Count > 1)
                {
                    KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Can't grab", "(" + part.children.Count + " parts is attached to it)");
                    return;
                }
            }

            // Grab icon
            if (part.children.Count > 0 || part.parent)
            {
                KISAddonCursor.CursorEnable("KIS/Textures/grabOk", "Detach & Grab", '(' + part.partInfo.title + ')');
            }
            else
            {
                KISAddonCursor.CursorEnable("KIS/Textures/grabOk", "Grab", '(' + part.partInfo.title + ')');
            }

            part.SetHighlight(true, false);
            grabOk = true;
        }
        void OnMouseDetachEnterPart(Part part)
        {
            if (!detachActive)
            {
                return;
            }
            detachOk = false;
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }
            if (KISAddonPointer.isRunning)
            {
                return;
            }
            if (hoverInventoryGui())
            {
                return;
            }
            if (draggedPart)
            {
                return;
            }
            ModuleKISPartDrag  pDrag       = part.GetComponent <ModuleKISPartDrag>();
            ModuleKISItem      item        = part.GetComponent <ModuleKISItem>();
            ModuleKISPartMount parentMount = null;

            if (part.parent)
            {
                parentMount = part.parent.GetComponent <ModuleKISPartMount>();
            }

            // Do nothing if part is EVA
            if (part.vessel.isEVA)
            {
                return;
            }

            // Check part distance
            if (!HasActivePickupInRange(part))
            {
                KISAddonCursor.CursorEnable("KIS/Textures/tooFar", "Too far", "(Move closer to the part)");
                return;
            }


            // Check if part is static attached
            if (item)
            {
                if (item.staticAttached)
                {
                    ModuleKISPickup pickupModule = GetActivePickupNearest(part, canStaticAttachOnly: true);
                    if ((item.allowStaticAttach == 1) || (pickupModule && item.allowStaticAttach == 2))
                    {
                        part.SetHighlightColor(XKCDColors.Periwinkle);
                        part.SetHighlight(true, false);
                        KISAddonCursor.CursorEnable("KIS/Textures/detachOk", "Detach from ground", '(' + part.partInfo.title + ')');
                        detachOk = true;
                        return;
                    }
                    else
                    {
                        if (FlightGlobals.ActiveVessel.isEVA)
                        {
                            KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(This part can't be detached from the ground without a tool)");
                            return;
                        }
                        else
                        {
                            KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach from ground function is not supported on this part)");
                            return;
                        }
                    }
                }
            }


            // Check if part can be detached
            if (!parentMount)
            {
                if (part.children.Count > 0 || part.parent)
                {
                    //Part with a child or a parent
                    if (item)
                    {
                        if (item.allowPartAttach == 0)
                        {
                            KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Can't detach", "(This part can't be detached)");
                            return;
                        }
                        else if (item.allowPartAttach == 2)
                        {
                            ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true);
                            if (!pickupModule)
                            {
                                if (FlightGlobals.ActiveVessel.isEVA)
                                {
                                    KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(Part can't be detached without a tool)");
                                    return;
                                }
                                else
                                {
                                    KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach function is not supported on this part)");
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true);
                        if (!pickupModule)
                        {
                            if (FlightGlobals.ActiveVessel.isEVA)
                            {
                                KISAddonCursor.CursorEnable("KIS/Textures/needtool", "Tool needed", "(Part can't be detached without a tool)");
                                return;
                            }
                            else
                            {
                                KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Not supported", "(Detach function is not supported on this part)");
                                return;
                            }
                        }
                    }
                }
                else
                {
                    // Part without childs and parent
                    return;
                }
            }

            // Check if part is a root
            if (!part.parent)
            {
                KISAddonCursor.CursorEnable("KIS/Textures/forbidden", "Root part", "(Cannot detach a root part)");
                return;
            }

            // Detach icon
            part.SetHighlightColor(XKCDColors.Periwinkle);
            part.SetHighlight(true, false);
            part.parent.SetHighlightColor(XKCDColors.Periwinkle);
            part.parent.SetHighlight(true, false);
            KISAddonCursor.CursorEnable("KIS/Textures/detachOk", "Detach", '(' + part.partInfo.title + ')');
            detachOk = true;
        }
 void OnDragReleased()
 {
     KISAddonCursor.CursorDefault();
     if (HighLogic.LoadedSceneIsFlight)
     {
         InputLockManager.RemoveControlLock("KISpickup");
         // Re-enable jetpack mouse control (workaround as SetControlLock didn't have any effect on this)
         KerbalEVA Keva = FlightGlobals.ActiveVessel.rootPart.GetComponent <KerbalEVA>();
         if (Keva)
         {
             if (jetpackLock)
             {
                 Keva.JetpackDeployed = true;
                 jetpackLock          = false;
                 KIS_Shared.DebugLog("Jetpack mouse input re-enabled");
             }
         }
     }
     if (hoverInventoryGui())
     {
         // Couroutine to let time to KISModuleInventory to catch the draggedPart
         StartCoroutine(WaitAndStopDrag());
     }
     else
     {
         ModuleKISPartDrag pDrag = null;
         if (KISAddonCursor.hoveredPart)
         {
             if (KISAddonCursor.hoveredPart != draggedPart)
             {
                 pDrag = KISAddonCursor.hoveredPart.GetComponent <ModuleKISPartDrag>();
             }
         }
         if (pDrag)
         {
             if (draggedItem != null)
             {
                 draggedItem.DragToPart(KISAddonCursor.hoveredPart);
                 pDrag.OnItemDragged(draggedItem);
             }
             else
             {
                 pDrag.OnPartDragged(draggedPart);
             }
         }
         else
         {
             if (HighLogic.LoadedSceneIsEditor)
             {
                 if (draggedItem != null)
                 {
                     draggedItem.Delete();
                 }
             }
             if (HighLogic.LoadedSceneIsFlight)
             {
                 if (draggedItem != null)
                 {
                     Drop(draggedItem);
                 }
                 else
                 {
                     movingPart = draggedPart;
                     Drop(movingPart, movingPart);
                 }
             }
         }
         icon        = null;
         draggedPart = null;
     }
     KISAddonCursor.StopPartDetection();
 }