Computer Science Canada

[Tutorial] How to use a mouse in your Turing programs

Author:  Dan [ 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.

Author:  KeN [ Tue Sep 24, 2002 6:02 am ]
Post subject: 

Great tutorial.

Perhaps you know the code for when you click and object for it to perform something with the mouse.

Author:  Tony [ Tue Sep 24, 2002 2:03 pm ]
Post 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 Wink

Author:  Stuperman [ Fri Nov 29, 2002 4:41 am ]
Post subject: 

sweet

Author:  cutecotton [ Mon Dec 23, 2002 1:08 am ]
Post 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.

Author:  Tony [ Mon Dec 23, 2002 2:11 am ]
Post 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

Author:  cutecotton [ Mon Dec 23, 2002 2:35 am ]
Post subject: 

tks tha'ts just waht i needed...^^

Author:  JSBN [ 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

Author:  Vicous [ 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

Author:  TheFreshPrince [ Tue May 04, 2004 7:48 pm ]
Post subject: 

thnx for the help

Author:  Flashkicks [ Fri May 07, 2004 7:41 am ]
Post 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!!! Wink

Author:  Dan [ Fri May 07, 2004 11:59 am ]
Post 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.

Author:  The_Triangle [ Thu Nov 24, 2005 5:39 am ]
Post 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 Laughing and the mouse hand didnt show up.
Any one know how to do this ?

Author:  Tony [ Thu Nov 24, 2005 9:17 am ]
Post subject: 

The mouse is controlled by OS, therefor you'd require system API.. something outside of Turing's scope.

Author:  The_Triangle [ Thu Nov 24, 2005 4:19 pm ]
Post subject: 

Tony wrote:
The mouse is controlled by OS, therefor you'd require system API.. something outside of Turing's scope.


nooo like i mean how people do the mousehand thing in flash games, and msn has it to ... if that helps ya

Author:  Tony [ Thu Nov 24, 2005 4:32 pm ]
Post subject: 

Flash and MSN weren't made with Turing Wink

Author:  MysticVegeta [ Thu Nov 24, 2005 6:26 pm ]
Post subject: 

This can be done in VB right?

Author:  Tony [ Thu Nov 24, 2005 7:14 pm ]
Post subject: 

anything with Windows API access. VB is pretty simple, there are code sniplets available all over the place (MSDN?).

Author:  The_Triangle [ Thu Nov 24, 2005 8:24 pm ]
Post subject: 

what does Windows API access stand for?

And why doesnt turing have access to it ? Wouldnt it be so much easier... damn.. lol

Author:  Tony [ Thu Nov 24, 2005 8:36 pm ]
Post subject: 

no, it would make things unneccessary complicated - that's why.

you'd need to hook Turing into the OS, and perform all those low level operations. Not something you teach highschool students.. or want them to be able to use for that matter.

Just imagine - program calls a command to make mouse cursor invisible, then quits. Oh damn it, you've just lost your mouse until you reboot or write another program to fix things.

Author:  [Gandalf] [ Fri Nov 25, 2005 3:33 pm ]
Post subject: 

API stands for Application Program Inferface.

Author:  Dan [ Sun Nov 27, 2005 7:57 pm ]
Post subject: 

Tony wrote:

Just imagine - program calls a command to make mouse cursor invisible, then quits. Oh damn it, you've just lost your mouse until you reboot or write another program to fix things.


And thats why VB is a script kiddys dream.

Author:  [Gandalf] [ Mon Nov 28, 2005 1:04 am ]
Post subject: 

Maybe if you edited the executable, and changed the cursor there? Just an idea...

Author:  Tony [ Mon Nov 28, 2005 9:23 am ]
Post subject: 

you could Sys.Exec() VB programs that change cursors for you.

Author:  progammin_nub [ Thu May 11, 2006 10:16 pm ]
Post subject:  Some part of my coding.

%The status of my mouse
buttonwait ("down", mx, my, buttonnumber, buttondown)

Hello,
I am just wondering for the mouse status for my program. When I specify "down", will Turing automatically tells itself to wait for the button to be pressed?

Author:  Anonymous [ Sat Jun 17, 2006 10:36 pm ]
Post subject:  Multi-Button

You forgot to mention Multi-Button, since it wasn't out when you posted this I guess. As you would assume, Multi-Button allows left click, right click, and middle click on Windows (possibly Mac I don't know). At the top of your program, declare:
code:

Mouse.ButtonChoose("multibutton")


Now you should set your mouse variables, here's my example:
code:

var x, y, button, none, left, middle, right : int
%Numbers below represent button values
none := 0
left := 1
middle := 10
right := 100


Next you must locate your mouse and status, usually in a loop.
Here I will display current mouse information:
code:

loop
    Mouse.Where (x, y, button)
    locate (1, 1)
    put "X:", x, " Y:", y
    if button = none then
        put "NOTHING ", button
    elsif button = left then
        put "LEFT ", button
    elsif button = middle then
        put "MIDDLE ", button
    elsif button = right then
        put "RIGHT ", button
    end if
end loop


Put those three pieces of code together to have a fully functional multi-button mouse!

Author:  gohabsgo007 [ Mon Dec 08, 2014 5:11 pm ]
Post subject:  Re: [Tutorial] How to use a mouse in your Turing programs

I want to know how to make a picture, uploaded from my computer, to move when the user clicks on it. Confused

Author:  Insectoid [ Mon Dec 08, 2014 7:43 pm ]
Post subject:  RE:[Tutorial] How to use a mouse in your Turing programs

Easy. Upload a picture from the computer, check if the user clicks on it, then move it.

Author:  gohabsgo007 [ Tue Dec 09, 2014 4:54 pm ]
Post subject:  Re: [Tutorial] How to use a mouse in your Turing programs

BooHoo


: