Page 1 of 1

ExamineMouse *Solved, Props to netmaestro*

Posted: Mon Jul 17, 2006 10:59 am
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

Posted: Mon Jul 17, 2006 4:06 pm
by Konne
Because ExamineMouse is for Games. If u do not use a screen use other commands. (Look Window Lib Help)

Posted: Mon Jul 17, 2006 4:52 pm
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.

Posted: Fri Aug 25, 2006 5:54 am
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.

Posted: Fri Aug 25, 2006 6:08 am
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)

Posted: Fri Aug 25, 2006 7:24 am
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.

Posted: Fri Aug 25, 2006 7:55 am
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 

Posted: Fri Aug 25, 2006 8:02 am
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)

Posted: Fri Aug 25, 2006 8:06 am
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.

Posted: Fri Aug 25, 2006 8:20 am
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*