Mouse outside of windowed app

I am trying to make it so that my mouse converts to the hardware mouse when I move the cursor outside of the window.  I have a custom mouse and this method is called inside of its move action.



The problems are:

1- The in game cursor comes back at random points when moving the hardware cursor around.  Not at the edges like it should.

2- When leaving the window the cursor flashes briefly in the center of the screen and then is moved to the edge of the window by the setCursorPosition call.  I tried switching the calls so that it moved before it was set visible but then it was not moved at all.

MouseInput.get().setCursorVisible(true);

MouseInput.get().setCursorPosition( (int)hotSpotLocation.x, (int)hotSpotLocation.y);




private void testMove()
{
   hotSpotLocation.y += mouseInput.getYDelta() * speed;
   hotSpotLocation.x += mouseInput.getXDelta() * speed;
   
   // Check if the cursor is outisde of the window
   if ( hotSpotLocation.y > height - 1 || hotSpotLocation.y < 0 ||
       hotSpotLocation.x > width - 1  || hotSpotLocation.x < 0 )
   {
      if ( MouseInput.get().isCursorVisible() == false )
      {
         GameTaskQueueManager.getManager().update(new Callable<Object>() {
             public Object call() throws Exception {
                MouseInput.get().setCursorVisible(true);
                MouseInput.get().setCursorPosition( (int)hotSpotLocation.x, (int)hotSpotLocation.y);
                 return null;
             }
         });
         
      }
   }
   else
   {
      if ( MouseInput.get().isCursorVisible() == true )
      {
         GameTaskQueueManager.getManager().update(new Callable<Object>() {
             public Object call() throws Exception {
                MouseInput.get().setCursorVisible(false);
                 return null;
             }
         });
      }
      
      localTranslation.x = hotSpotLocation.x - hotSpotOffset.x;
      worldTranslation.x = localTranslation.x;
      absX = hotSpotLocation.x;
      
      localTranslation.y = hotSpotLocation.y - hotSpotOffset.y;
      worldTranslation.y = localTranslation.y;
      absY = hotSpotLocation.y;
   }
}