Page 3 of 3

Posted: Tue Feb 06, 2007 8:50 pm
by Kaeru Gaman
you use GetAsyncKeyState_(#VK_LBUTTON) also in the part for the right button.
I guess you just forgot to change it after copy/paste...

and:

Code: Select all

              If GetAsyncKeyState_(#VK_LBUTTON) & 32768 
                ;...
              EndIf 
              If Not GetAsyncKeyState_(#VK_LBUTTON) & 32768 
                ;...
              EndIf 
the second if will call GetAsyncKeyState again, thus it's no longer the first click.
replace the second If by an ELSE


additionally:
if I remember correctly, the &32768 is for registrating the first click.
if you want the behaviour like ExamineMouse/ExamineKeyboard you should leave the &32768 out.

in my example I have once per Frame a single call for each button:

Code: Select all

    MLC = GetAsyncKeyState_(#VK_LBUTTON) 
    MRC = GetAsyncKeyState_(#VK_RBUTTON) 
after that I can check MLC as often as I want with every bitcheck I want,
without having called GetAsyncKeyState more than once.

Posted: Tue Feb 06, 2007 9:01 pm
by netmaestro
if I remember correctly, the &32768 is for registrating the first click.
Not sure where you got that, but if the most significant bit is set the key is down. If it's not set, the key is up. No exceptions and no other bits in the return value relate to the up-or-down status of the key. So good coding practice is to mask it.

Posted: Tue Feb 06, 2007 9:02 pm
by Matt
If I make those changes, holding the mouse down will keep debugging 'left clicked' for some reason.

Posted: Tue Feb 06, 2007 9:08 pm
by netmaestro

Posted: Tue Feb 06, 2007 9:25 pm
by Kaeru Gaman
netmaestro wrote:
if I remember correctly, the &32768 is for registrating the first click.
Not sure where you got that, but if the most significant bit is set the key is down. If it's not set, the key is up. No exceptions and no other bits in the return value relate to the up-or-down status of the key. So good coding practice is to mask it.
ok, so I mixed it up with another bit.
there is one that is only TRUE on the first call with the button down.

nevertheless, passing the return-value to a variable is still a good idea.
If I make those changes, holding the mouse down will keep debugging 'left clicked' for some reason.
this is because the button is still down. same should apply using ExamineMouse.

as said above, there is another bit than bit15 that is only set on the first test.

the procedures netmaestro linked are quite nice, but they still have the problem that
GetAsyncKeyState can get called more than once a frame wich is something you should avoid.

Re: Mouse in screen + MOUSEWHEEL

Posted: Tue Nov 09, 2010 2:48 pm
by hth
I need inside the loop in addition to query the mouse wheel.

Code: Select all

InitSprite() : InitKeyboard()

OpenScreen(640,480,16,"untitled")
ShowCursor_(1)
SetClassLong_(ScreenID(),#GCL_HCURSOR,LoadCursor_(0,#IDC_ARROW))

Repeat   
   ClearScreen($854422)   
   
   ExamineKeyboard() 
   
   StartDrawing(ScreenOutput())   
   If GetAsyncKeyState_(#VK_LBUTTON)
      DrawText(10,10,"MOUSE INPUT: LEFT BUTTON")   
   ElseIf GetAsyncKeyState_(#VK_MBUTTON)
      DrawText(10,10,"MOUSE INPUT: MIDDLE BUTTON")
   ElseIf GetAsyncKeyState_(#VK_RBUTTON)
      DrawText(10,10,"MOUSE INPUT: RIGHT BUTTON")

    ; MOUSWHEEL ??????????

   Else
      DrawText(10,10,"MOUSE INPUT: IDLE")
   EndIf
   
   GetCursorPos_(cpt.POINT)   
   DrawText(10,40,"MOUSE POSITION: " + Str(cpt\x) + "," + Str(cpt\y))
   StopDrawing()
   
   FlipBuffers()
Until KeyboardPushed(1)
hth

Re: Mouse in screen

Posted: Tue Nov 09, 2010 4:17 pm
by #NULL
there is no virtual key for the mouse wheel. you either have to catch a #WM_MOUSEWHEEL event (i don't know how to do this for a fullscreen), or you simply use the pb mouse lib.

Re: Mouse in screen

Posted: Tue Nov 09, 2010 7:24 pm
by hth
Unfortunately kills ExamineMouse() the mouse pointer.

hth