Mouse trouble

Advanced game related topics
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Mouse trouble

Post by Matt »

I'm having a little trouble with getting mouse events, since only MouseButton is the only function I see that PureBasic has...
I need to check whether the left mouse button was clicked, the right mouse button was clicked, if the left mouse button is being pressed, and if the right mouse button is being pressed.

I'm having a little trouble doing those things, of course I am able to use MouseButton to check whether they are being pressed, but what about being clicked?
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

You will need to code your own routine if you are using a fullscreen, I think.
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Post by Matt »

Yeah I'm using full screen
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

I assume you have some kind of gadgets to click on or something, are you asking for double clicks or just straight forward clicking on an object kind of thing?
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Post by Matt »

There will be a sprite taking up the whole screen in the full screen mode.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

You can always count how long the mousebutton has been down.
Try this.

Code: Select all

InitSprite()
InitMouse()
InitKeyboard()
OpenWindow(0,0,0,800,200,"")
OpenWindowedScreen(WindowID(0),0,0,800,200,0,0,0)
ticks=0
flag=0
ExamineKeyboard()

While Not KeyboardPushed(#PB_Key_Escape)
  WaitWindowEvent()
  Delay(1)
  ExamineMouse()

  If MouseButton(#PB_MouseButton_Left)=1
    ticks+1
    flag=1
  EndIf

  If MouseButton(#PB_MouseButton_Left)=0
    If flag=1
      If ticks<6
        Debug "Clicked"
      Else
        Debug "Held down"
      EndIf
      flag=0
      ticks=0
    EndIf
  EndIf

  ExamineKeyboard()
Wend
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Post by Matt »

-edit-

thank you, this works perfect :)
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Your welcome.
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Post by Matt »

To suit what I needed I also needed to figure out when it was starting to be pressed.
So here is what I added, in case anybody would like to know.

Thanks again Derek

Code: Select all

InitSprite()
InitMouse()
InitKeyboard()
OpenWindow(0,0,0,800,200,"")
OpenWindowedScreen(WindowID(0),0,0,800,200,0,0,0)
ticks=0
flag=0
pressed=0
ExamineKeyboard()

While Not KeyboardPushed(#PB_Key_Escape)
  WaitWindowEvent()
  Delay(1)
  ExamineMouse()

  If MouseButton(#PB_MouseButton_Left)=1
    ticks+1
    flag=1

    If ticks >= 200 And pressed = 0
      Debug "left pressed"
      pressed = 1
    EndIf
  EndIf

  If MouseButton(#PB_MouseButton_Left)=0
    If flag=1
      If ticks<200
        Debug "left clicked"
      Else
        Debug "left released"
      EndIf
      flag=0
      ticks=0
      pressed = 0
    EndIf
  EndIf

  ExamineKeyboard()
Wend 
Post Reply