ExamineMouse *Solved, Props to netmaestro*

Just starting out? Need help? Post your questions and find answers here.
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

ExamineMouse *Solved, Props to netmaestro*

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

Why does examine mouse:

+-+ Prevent the cursor from leaving the window
+-+ Hide the default cursor

Is there a way to stop both those effects?

Thanks,

Ori
Last edited by ..::Origin::.. on Fri Aug 25, 2006 8:30 am, edited 1 time in total.
Konne
Enthusiast
Enthusiast
Posts: 434
Joined: Thu May 12, 2005 9:15 pm

Post by Konne »

Because ExamineMouse is for Games. If u do not use a screen use other commands. (Look Window Lib Help)
Apart from that Mrs Lincoln, how was the show?
Jan Vooijs
Enthusiast
Enthusiast
Posts: 196
Joined: Tue Sep 30, 2003 4:32 pm
Location: The Netherlands

Post by Jan Vooijs »

Correct see the manual this snipit from the help file:

Code: Select all

PureBasic provides a full access to mices plugged to the computer. It supports standard mouses upto 3 buttons. This library is optimized and use very low level functions especially for use with games. Don't use the commands of this library in a regular application, in this case carry out the mouse query with WindowMouseX(), WindowMouseY() and EventType(). Under Windows the DirectX technology is used. 
Jan V.
Life goes to Fast, Enjoy!!

PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!

AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

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

Well, with a windowed screen, the cursor just refuses the leave the screen, so i need to be able to move the cursor OUT of the screen and still have the screen functioning.
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 »

If you need access to the whole desktop when you're running a windowed screen application or game, you can't do InitMouse() and ExamineMouse() and you can't use the commands in the Mouse library. PureBasic or API substitutes exist for all these commands and you'll need to use those:

MouseX(), MouseY(): WindowMouseX(), WindowMouseY()
MouseDeltaX(), MouseDeltaY(): compute these with code from earlier values
MouseLocate(): MapWindowPoints_(), SetCursorPos_()
MouseButton(): GetAsyncKeyState_(#VK_LBUTTON), GetAsyncKeyState_(#VK_RBUTTON)
BERESHEIT
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

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

Ah-ha, sweet. So it was acctualy my engine and not the functions screwing up on me.

I've re-written my engine to work with these functions instead, although i've found that WindowMouseX()/WindowMouseY() wont be reported unless the mouse has acctualy moved in the window.

I'm thinking of something that may fix this, any advice would be good.

Edit: No, it did not work.
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