Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Mouse Codes??

Author
Message
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 17th Jun 2009 04:58
Ok i have a 3 button mouse and im trying to work out the codes for it.

What i need is the clicks for button 1,2 and 3 and the releases also, is there any codes for that...

your help is greatly appreciated..

Come and have a look at my hobby site once your ready..
http://darkdstudio.webs.com/
Note: its still really bare..
Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, <looks around.>
Posted: 17th Jun 2009 05:25
Well, mouseclick()=1 means button one in pressed,
mouseclick()=2 means button two is pressed,
and mouseclick()=4 means button three is pressed,
and mouseclick()=3 means buttons one and two are pressed (1+2), thus each unique button would be the next unique number that cannot be the sum of any previous button_values.

As far as detecting releases, you need to just see if the return value of the mouseclick() function is equal to zero, or not equal to its corresponding button_value.
lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 17th Jun 2009 07:18
ok i thaught of another way of doing it, i tried to make it into a function but the variables arent returning properly for some reason..


heres the function



and how to use it



and this is it without the function



Come and have a look at my hobby site once your ready..
http://darkdstudio.webs.com/
Note: its still really bare..
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 17th Jun 2009 18:41 Edited at: 17th Jun 2009 18:44
CRelease isn't a global variable so it will just equal 0 whenever you try to use it outside of the function. In this case, CRelease is local. This means that whenever you call that function, it uses its own version of CRelease, not the CRelease you see outside of the function.

Having said that, your function returns a value. This means that if you set a variable equal to that function, then the variable will equal the value returned. To make your code work you can do one of two things:

1.
Change this:


to this:


So your end code is:


What that does is set the CRelease variable used outside of the function to the value returned from the function. Since you return the number in the function's own version of the CRelease variable, you are essentially setting the external CRelease variable to the function's internal one. You could just as easily do this:



and use "roflcopter" as your variable, doing this:



2.
The second thing you could do is declare CRelease as a global variable:


and have the function return nothing at all. What the GLOBAL command basically does is it makes a variable have no internal version so that functions have to use the same version that the main program and all of the other functions use. This means that you could change a variable without returning a value at all.

<-- Spell based team dueling game!
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 17th Jun 2009 21:36
When checking if a mouse button is down don't use 'If MouseClick() = ', use 'If MouseClick() &&'. If you use '=' then you're not accounting for multiple buttons being pressed at once.

Try out this snippet:



then this one:



The difference is that the second one tells you if multiple buttons are being pressed simultaneously, whereas the first only tells you if a single button is being pressed.

i like orange
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 17th Jun 2009 23:04
@AndrewT:
I didn't know that! That && thing has been added to my big book of coding wisdom!

Does it have a name?

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 18th Jun 2009 00:07 Edited at: 18th Jun 2009 00:22
It's the bitwise AND operator. It takes the bits of two numbers, and if they're both 1 then the result is a 1, otherwise its a 0.

Ex.

%00110011 &&
%00010110 =
%00010010

See how it works?

This works with the mouse buttons, because the left button is represented by the number %0001, the right by %0010, and the middle by %0100. So if you have the left and right buttons pressed down you get:

%0001 (left button) +
%0010 (right button) =
%0011

To check if the left button is down you'd do

if mouseClick() && %0001 (or 1)

and to check if the right button is down you'd do

if mouseClick() && %0010 (or 2)

and to check the middle you'd use

if mouseClick() && %0100 (or 4)

There are also other bitwise operators:

The bitwise OR operator - || - results in a 1 if either bit is 1:

%00110011 ||
%00010110 =
%00110111

The bitwise XOR (exclusive or) operator - ~~ - results in a 1 if exactly one of the two bits is a 1:

%00110011 ~~
%00010110 =
%00100101

The bitwise left shift operator - << - shifts each bit to the left by the specified number:

%00110011 << 2 = %11001100

And there's also a bitwise right shift (>> but I think it's self-explanatory.

i like orange
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 18th Jun 2009 22:43
Quote: "This works with the mouse buttons, because the left button is represented by the number %0001, the right by %0010, and the middle by %0100. So if you have the left and right buttons pressed down you get:"


Oh!



Diggsey: I have a spine and memory, but one memorable guy says he hates me. What am I?
Pillarofire
20
Years of Service
User Offline
Joined: 31st Dec 2003
Location: Good Question, &lt;looks around.&gt;
Posted: 19th Jun 2009 04:15
@AndrewT:
Brilliant! This is definitely (((%10 && %10) || %01) >> 1). Thanks for the enlightenment.

Login to post a reply

Server time is: 2024-11-25 05:00:42
Your offset time is: 2024-11-25 05:00:42