Why does #PB_MouseButton... seems not to work?

Everything else that doesn't fall into one of the other PB categories.
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Why does #PB_MouseButton... seems not to work?

Post by va!n »

i have a little codesnip opening a windowedscreen and showing a window in front of the screen (code can be found on "coding help" topic") ... i have tried to detect left and right mouseclick on the screen with the mouse keywords... following example showing only the theorie of what i use... why does it not work? even when a MsgReq pop up and pressing ENTER instead left mousebutton, it pop up again and again! Even i use Examinemouse() - is there a bug? Trying to press ESC after one MsgReq is poped up, you can exit anymore...

I could use keycommands instead mouse... but using left/right mousebutton would make live a lot more easy ,)

Code: Select all

InitSprite()
InitKeyboard()
InitMouse()

OpenScreen(800,600,32,"Test")
ShowCursor_(#True)

Repeat
  ExamineMouse()
  ExamineKeyboard()
  ClearScreen(0)
  
  If MouseButton( #PB_MouseButton_Left)
    MessageRequester("LMB","",0)
  EndIf
  
  If MouseButton( #PB_MouseButton_Left)
    MessageRequester("RMB","",0)
  EndIf
  
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

possible a bug in pb? because why does KeyboardPushed does not work when pressed any mouse button before?? maybe its just to late for me and i should sleep a bit ;)
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

The messagerequester isn't appropriate for this kind of test. Try this:

Code: Select all

InitSprite() 
InitKeyboard() 
InitMouse() 

ExamineDesktops()
OpenScreen(DesktopWidth(0),DesktopHeight(0),DesktopDepth(0),"Test") 

Repeat 
  ExamineMouse() 
  ExamineKeyboard() 
  ClearScreen(0) 
  
  If MouseButton( #PB_MouseButton_Left) 
   StartDrawing(ScreenOutput())
     DrawText(320,290,"LEFT MOUSEBUTTON",#Red,#Black)
   StopDrawing()
  EndIf 
  
  If MouseButton( #PB_MouseButton_Right) 
   StartDrawing(ScreenOutput())
     DrawText(320,290,"RIGHT MOUSEBUTTON",#Red,#Black)
   StopDrawing()
  EndIf 
  
  FlipBuffers() 
Until KeyboardPushed(#PB_Key_Escape) 
End 
The test will be true as long as the mousebutton is held down and go false as soon as it's released, which is just the right behavior for making games.
BERESHEIT
Post Reply