Posted: Tue Aug 20, 2002 9:14 pm Post subject: [Tutorial] How to use a mouse in your Turing programs
How to use a mouse in Turing
This is a simple code but it can be hard to keep on finding out where the mouse is at all times.
The mouse code:
Mouse.Where (X, Y, Button) %all values are int's
X is the x quadrant of the mouse
Y is the y quadrant of the mouse
Button is 0 if the button on the mouse is not down and is 1 if the button is down on the mouse. Note: this is only true if the mouse is set to single-button mode; it should be by default.
How to use this code:
code:
var x, y, button :int %vars for the mouse where code
loop %needs to be in a loop to keep on reading mouse data
Mouse.Where (x, y, button) %code to find data on mouse
locatexy (x,y) %locate the text to the same line as x&y
put " ", x, " ", y %put mouse location
%check to see if button is hit
if button = 1 then
locatexy (maxx div 2,maxy div 2)
put "you clicked the button"
delay (1000)
cls
end if
cls
end loop
Note if you want to make a game or program that uses a mouse you should have the mouse where command in some kind of loop to keep on getting the quadrants of the mouse.
This was my 2nd Tutorial for this borad, plz re and tell me what you think about it.
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Sponsor Sponsor
KeN
Posted: Tue Sep 24, 2002 6:02 am Post subject: (No subject)
Great tutorial.
Perhaps you know the code for when you click and object for it to perform something with the mouse.
Tony
Posted: Tue Sep 24, 2002 2:03 pm Post subject: (No subject)
VB would be great for that since its object oreanted. (Winoot doesn't mean shit, it's still text based)
Otherwise, in turing you can run a check to see if sertain object is clicked on or not, such as in
code:
Mouse.Where(x,y,b)
If b = 1 %mouse down
then
if x> left side of object and x < right side of object
and y>bottom side of object and y < top side of object
%basically you clicked inside the rectangle object
then
%do whatever
end if
end if
don't forget to put all that in a loop, otherwise it will check for mouse status only once
Posted: Fri Nov 29, 2002 4:41 am Post subject: (No subject)
sweet
cutecotton
Posted: Mon Dec 23, 2002 1:08 am Post subject: (No subject)
very nice, and really helpful..i just got a litte question related to mouse-use in turing. I know there's a way to do this. So let's say you ahve a box at the bottom, and everytime the user rolls thier mouse of it, the box will turn blue. How can you do that? but the user wont' have to click in order for the box to turn blue, just rolling thier mouse over it does that.
Tony
Posted: Mon Dec 23, 2002 2:11 am Post subject: (No subject)
well then you just check for the mouse location... such as
code:
loop
Mouse.Where(x,y,b)
if y < 100 then
colorback(black)
cls
else
colorback(white)
cls
end if
end loop
Posted: Mon Dec 23, 2002 2:35 am Post subject: (No subject)
tks tha'ts just waht i needed...^^
JSBN
Posted: Thu Jan 30, 2003 5:21 pm Post subject: Mouse
here's my little tutorial for using the mouse it explains everything
Basically i have cut and pasted from games i got from this site & put it into a nice little, well documeted program.
F.Y.I - there is an alternative method to figure out when the mouse button is clicked(which i prefere because this one can cause problems). I put it at the bottom after this main code.
code:
%This is a simple mouse where? program.
%It was made by James Boelen with the help of S.W.A.T.
%-------------------------------------------------------------------------------
%Ok these variables are for the mouse axis' because a mouse has 3 axis,
%we need 3 variables. mx=Xaxis my=Yaxis mb=the mouse button. you need to have
%all three for the program to function correctly, but for our uses, only need to
%worry about the X & Y axis. Each one will be getting a number, so we declare
%them as int and make them equal 0.
var mx, my, mb : int := 0
%we loop the program because we ca better see the effect.
loop
%this command finds the mouse position on the screen.
mousewhere (mx, my, mb)
if my > 390 then
my := 390
elsif my < 10 then
my := 10
end if
%and we draw something at the mouses's XYcords.
drawfilloval (mx, my, 10, 10, black)
%ends when the mouse button is pushed
exit when buttonmoved ("down")
end loop
here's that extra code:
code:
%mb is the declare of the mouse button it the above code...
if mb=1 then
for i:1..20
delay (20)
drawfilloval (mx, my, 10+i, 10+i, red)
end for
drawfilloval (mx, my, 30, 30, white)
end if
Sponsor Sponsor
Vicous
Posted: Mon Mar 03, 2003 6:28 am Post subject: advanced mouse work
I was reading the help section, and I get the idea that gui has more advanced mouse functions, how about a more advanced mouse titorial (I know that's not spelled right, I just can't think of the correct spelling right now) like with buttons and such
TheFreshPrince
Posted: Tue May 04, 2004 7:48 pm Post subject: (No subject)
thnx for the help
Flashkicks
Posted: Fri May 07, 2004 7:41 am Post subject: (No subject)
I think if you are going to post a tutorial- you should add as MUCH of information regarding the command/predefined command as it is possible for that command to use. Baically, a tutorial that for one answers all the questions you have seen been asked thus far; and two- explaining the other functions the mouse can do as well. Such as right clicking and so on. That is just my thoughts though.. Nothing too important really. Good job man!!!
Dan
Posted: Fri May 07, 2004 11:59 am Post subject: (No subject)
well if u checked the date on the tutorial u whould know that i made it b4 turing 4.x was out yet. So i belive all the Mouse.somting comands did not yet existed.
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
The_Triangle
Posted: Thu Nov 24, 2005 5:39 am Post subject: (No subject)
anyone know how to make the mouse scroll over a button in a game, and for instance like in a game, the mouse turns into the hand bar while it is scrolled over a button? im tryin to make that work in my game, no such luck. I tried finding that hand picture of the mouse but no luck finding it either, i also tried snapshotting the screen and the mouse hand didnt show up.
Any one know how to do this ?
Tony
Posted: Thu Nov 24, 2005 9:17 am Post subject: (No subject)
The mouse is controlled by OS, therefor you'd require system API.. something outside of Turing's scope.