Mouse in screen

Advanced game related topics
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
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 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.
BERESHEIT
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Post by Matt »

If I make those changes, holding the mouse down will keep debugging 'left clicked' for some reason.
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 »

BERESHEIT
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
hth
User
User
Posts: 41
Joined: Tue Aug 21, 2007 8:01 pm

Re: Mouse in screen + MOUSEWHEEL

Post 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
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Mouse in screen

Post 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.
hth
User
User
Posts: 41
Joined: Tue Aug 21, 2007 8:01 pm

Re: Mouse in screen

Post by hth »

Unfortunately kills ExamineMouse() the mouse pointer.

hth
Post Reply