Mouse.setGrabbed creates button presses for Mouse.next

Started by CuppoJava, April 02, 2005, 07:30:22

Previous topic - Next topic

CuppoJava

Hi,
I'm doing a simple input manager for my game, and I just noticed that whenever I initialize a window or call Mouse.setGrabbed(true), I get a whole whackload of reported mouse button presses even though I didn't click the mouse button. Here's the code I use to check for mouse presses:

while(Mouse.next())
{
  if(Mouse.getEventButton()>=0)
    System.out.println("mouse pressed");
}


Its kind of annoying, as I bound mouse presses to a save function. Now whenever the mouse is setGrabbed(true) it saves.

CuppoJava

Okay. I thought it would have been an easy workaround but I apparently not. I'm really stuck now.

I replaced my Mouse.next() routine with just calling
Mouse.isButtonDown(int button) but the method is giving me some strange replies.

Whenever I ungrab the mouse, Mouse.isButtonDown(0) always returns true. I don't know where the problem is...my code does not directly interfere with the Mouse, it just reads whether the buttons are down are not. Why does it report that the Left button is down when I'm not holding it down?

Thx for any help. I'll keep on fiddling around.

CuppoJava

   boolean f1;
    boolean m;
    private void mainloop() {
      if(Display.isCloseRequested()) {                     // Exit if window is closed
          done = true;
      }
      if(Keyboard.isKeyDown(Keyboard.KEY_F1) && !f1) {   
        Mouse.setGrabbed(false);                           //On F1 press - release the mouse
          f1 = true;                                     
      }
      if(!Keyboard.isKeyDown(Keyboard.KEY_F1)) {         
          f1 = false;
      }

      if(Mouse.isButtonDown(0))
      {
        if(!m)
        {
          Mouse.setGrabbed(true);           //On mouse press - grab the mouse
          m = true;
        }
      }
      else
        m = false;
    }


Ok I forced out a simple example. This is a modified mainloop method from anyone of Nehe's tutorials. I want it to grab the mouse when I left-click. and Release the mouse when I press F1.

The workaround is : THE MOUSE SHOULD NOT BE GRABBED BETWEEN THE BUTTON PRESS AND THE BUTTON RELEASE. The program should always wait for all mouse buttons to be released before grabbing the mouse.

Ok - I think that was the key. I hope this is of some use to someone in fixing this.