ExamineMouse *Solved, Props to netmaestro*

Just starting out? Need help? Post your questions and find answers here.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Code: Select all

; Yet another useless program from netmaestro 
; 
; Shows example procedures for using mouse commands in 
; windowed screens when you don't want the mouse captured 

Global LBTN_STATUS, RBTN_STATUS 

Procedure LeftButtonPushed() 
  If GetAsyncKeyState_(#VK_LBUTTON) & 32768 
    LBTN_STATUS = 1 
    ProcedureReturn #True 
  Else 
    ProcedureReturn #False 
  EndIf 
EndProcedure 

Procedure RightButtonPushed() 
  If GetAsyncKeyState_(#VK_RBUTTON) & 32768 
    RBTN_STATUS = 1 
    ProcedureReturn #True 
  Else 
    ProcedureReturn #False 
  EndIf 
EndProcedure 

Procedure LeftButtonReleased() 
  If GetAsyncKeyState_(#VK_LBUTTON) & 32768 
    LBTN_STATUS=1 
    ProcedureReturn #False 
  Else 
    If LBTN_STATUS 
      LBTN_STATUS=0 
      ProcedureReturn #True 
    Else 
      ProcedureReturn #False 
    EndIf 
  EndIf 
EndProcedure 

Procedure RightButtonReleased() 
  If GetAsyncKeyState_(#VK_RBUTTON) & 32768 
    RBTN_STATUS=1 
    ProcedureReturn #False 
  Else 
    If RBTN_STATUS 
      RBTN_STATUS=0 
      ProcedureReturn #True 
    Else 
      ProcedureReturn #False 
    EndIf 
  EndIf 
EndProcedure 

Procedure Locate(x,y) 
  cp.point 
  MapWindowPoints_(WindowID(0),0,@cp,1) 
  SetCursorPos_(cp\x+20, cp\y+20) ; 20 = Offset of WindowedScreen on Window 
  ProcedureReturn 
EndProcedure 

Procedure GetMouseX() 
  ProcedureReturn WindowMouseX(0)-20 ; 20 = Offset as above 
EndProcedure 

Procedure GetMouseY() 
  ProcedureReturn WindowMouseY(0)-20 
EndProcedure 

Procedure MouseInScreen() 
  If GetMouseX() >= 0 And GetMouseX() <= 480 And GetMouseY() >=0 And GetMouseY()<=440 
    ProcedureReturn #True 
  Else 
    ProcedureReturn #False 
  EndIf 
EndProcedure 

InitSprite() 
OpenWindow(0,0,0,640,480, "Windowed Screen Mouse Substitutes", #PB_Window_ScreenCentered|#PB_Window_SystemMenu) 
CreateGadgetList(WindowID(0)) 
TextGadget(0,520,20,110,20,"") 
TextGadget(1,520,60,110,20,"") 
TextGadget(2,520,100,110,20,"") 
TextGadget(3,520,140,110,20,"") 
ButtonGadget(4,520,180,110,20,"Set Cursor to 0,0") 
OpenWindowedScreen(WindowID(0),20,20,480,440,0,0,0) 
Repeat 
  ev=WindowEvent() 

  If ev=#PB_Event_Gadget 
    If EventGadget()=4 
      Locate(0,0) 
    EndIf 
  EndIf 
  
  If MouseInScreen() 
    outstr.s = Str(GetMouseX())+","+Str(GetMouseY()) 
  Else 
    outstr.s = "0,0" 
  EndIf 
  SetGadgetText(0,outstr) 
  
  If LeftButtonPushed() ; will test true while button is down 
    SetGadgetText(1, "LeftButton DOWN") 
  Else 
    SetGadgetText(1,"LefButton UP") 
  EndIf 
  
  If RightButtonPushed() ; will test true while button is down 
    SetGadgetText(2, "RightButton DOWN") 
  Else 
    SetGadgetText(2,"RightButton UP") 
  EndIf 
  
  If RightButtonReleased() ; only fires once on release 
    SetGadgetText(3, "RightButton Released") 
    Delay(300) 
    SetGadgetText(3,"")    
  EndIf 
  
  If LeftButtonReleased() ; only fires once on release 
    SetGadgetText(3, "LeftButton Released") 
    Delay(300) 
    SetGadgetText(3,"") 
  EndIf 
    
  Delay(1) 
Until ev=#WM_CLOSE 
Last edited by netmaestro on Fri Aug 25, 2006 10:33 am, edited 1 time in total.
BERESHEIT
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

Post by ..::Origin::.. »

Thanks, but i said i figured that out.

What i was saying is that i don't seem to get any response from WindowMouseX/WindowMouseY unless the mouse has done an action (leftclick/move)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

In the code I posted, the mouse position is being reported and displayed in each loop. If WindowMouseX() or Y() were not testing correctly, it would display 0,0 right away. As the coordinates always display correct, it is working. If it isn't working for you, perhaps you could post some code.
Thanks, but i said i figured that out.
Didn't mean to offend - just might as well post it all as post cut-out pieces of a demo.
BERESHEIT
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

Post by ..::Origin::.. »

Hmm, interesting. I just had a look at your example with the debug and it seems to do what i was hoping mine would do... I'll keep looking through mine, will edit when if something comes up.

Edit:

...WindowWaitEvent()...*Rolls Eyes* - EVIL!!

Argh, sorry for wasting your time or offending you(if i did) netmaestro.

Thanks alot for the help, i hope i can pay you back one day.

*Solved*
Post Reply