forums

TNT Basic Forums > Programming Q&A
mouse pressed
< Last Thread     Next Thread >
Author
Thread        Post A Reply

01-25-2008 03:00

Posted by:
Pokoleo

Location:
on my computer

Find more posts by Pokoleo

is there a way of finding out if the mouse button is down or up. the only way that I could think of doing this is "mouse button, or mouse press" but those are full clicks, and not separate if the mouse is up or down.

if you could help me with this, it surely would help.


-Pokoleo

01-25-2008 12:10

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Hi, are you trying to get when the mouse is pressed, or just unpressed?

'This code is from my Tile-Based Game Engine (TBGE):

'Put this at the top:
global int ButtonState[128], ClickState

And put this code at the bottom
procedure BS(int bid)'ButtonState
'ButtonState覧覧覧覧覧覧覧覧覧覧覧覧覧覧0=not pressed | 1=pressed | 2=Holding button | 3=Let go of button
If ButtonState[bid]=3 then ButtonState[bid]=0
If not pressed(bid) and ButtonState[bid]>0 then ButtonState[bid]=3
If not pressed(bid) and ButtonState[bid]<>3 then ButtonState[bid]=0
If pressed(bid) and ButtonState[bid]=1 then ButtonState[bid]=2
If pressed(bid) and ButtonState[bid]=0 then ButtonState[bid]=1
'覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧
end proc
procedure CS()'ClickState
'ClickState覧覧覧覧覧覧覧覧覧覧覧覧覧覧0=not clicking | 1=clicked | 2=Holding mouse button | 3=Let go of mouse button
If ClickState=3 then ClickState=0
If not mouse button and ClickState>0 then ClickState=3
If not mouse button and Clickstate<>3 then ClickState=0
If mouse button and ClickState=1 then ClickState=2
If mouse button and ClickState=0 then ClickState=1
'覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧
end proc


CS() & ClickState are for the mouse, BS() & ButtonState are for when a button is pressed or unpressed (or held down).

And the comments explain what ClickState's value means. :)

And you must call CS() or BS(buttonID) every frame.

Hope this helps!
Jacob

01-25-2008 22:24

Posted by:
Pokoleo

Location:
on my computer

Find more posts by Pokoleo

Clarification

I would like to clarify this to you...
I am trying to make a paint like program, and I want to be able to "drag" the corner of the rectangle. I also didn't get what int should be BS( here )

thanks for your help!

pokoleo

01-26-2008 23:12

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Yes, this is perfect to do that.

Check this code out:

global int ClickState
while not pressed(12) 'Q
cs()
if ClickState=1 'this checks if you just clicked
'start drag
else if ClickState=2 'checks if the mouse button is held
'perform drag
else if ClickState=3 'this checks if you released the mouse button
'release drag and set new parameters
end if
wend


And the BS(buttonID) is just the same, but for any button on the keyboard, look in the help under "Inputs"

If you need further help, ask here or on the irc channel (I guess I'll make a thread announcing it's opening :D).

Have fun!
Jacob

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.