Computer Science Canada Clicking mouse button |
Author: | ans4 [ Fri Oct 27, 2006 11:49 pm ] |
Post subject: | Clicking mouse button |
I'm new to Turing and I need some help. How can I exit a program after entering a variable and then clicking anywhere on the screen? I've tried doing this but it doesn't work. Quote: var a : string
loop put "Enter a" get a if Mouse.ButtonMoved ("down") then exit end if end loop |
Author: | jamonathin [ Sat Oct 28, 2006 12:20 am ] | ||||
Post subject: | |||||
Since you are nwe to Turing, you should realize that F10 will be your new best friend. Here is an example from it
A personal preference, i use mousewhere.
|
Author: | ans4 [ Sat Oct 28, 2006 12:33 am ] |
Post subject: | |
Thanks and I have another question. It is possible to exit a loop with a mouse click after a get command right? |
Author: | TokenHerbz [ Sat Oct 28, 2006 2:36 am ] |
Post subject: | |
yea! |
Author: | richcash [ Sat Oct 28, 2006 11:52 am ] | ||
Post subject: | |||
Yes, but you should put your button-detecting in a separate loop, because otherwise (if you stick your get statement in the loop) it will skip right past your checking of the mouse clicked and have another get. Do this :
|
Author: | ans4 [ Sat Oct 28, 2006 12:18 pm ] |
Post subject: | |
But how do I exit the loop with get statement in it by clicking it? |
Author: | richcash [ Sat Oct 28, 2006 12:34 pm ] | ||
Post subject: | |||
I'm not too sure what you're talking about. If you want several get statements to be executed separated by mouse clicks, do this :
|
Author: | ans4 [ Sat Oct 28, 2006 12:41 pm ] | ||
Post subject: | |||
richcash wrote: I'm not too sure what you're talking about. If you want several get statements to be executed separated by mouse clicks, do this :
Could you get out of the get statement just by clicking the mouse instead of pressing the enter key? |
Author: | richcash [ Sat Oct 28, 2006 12:58 pm ] | ||
Post subject: | |||
Oh, no, you can't use the get statement then. The get statement stops everything and waits for input (and for you to press enter). You'll need to use getch or Input.KeyDown. Something like this :
|
Author: | ans4 [ Sat Oct 28, 2006 1:24 pm ] |
Post subject: | |
Thanks, that one worked. Now is there a way to only exit when you click on a specific place on the screen? |
Author: | richcash [ Sat Oct 28, 2006 1:38 pm ] | ||
Post subject: | |||
Use the x and y passed to Mouse.Where, they are the coordinates of where the mouse is (which pixel the mouse is at). For a rectangular section (as I suspect you want), you need to check if the x of the mouse is between the x's of the box and the y's is between the y's of the box. If you don't know about drawing rectangles, look up Draw.FillBox in F10. Sample code :
Oh, and the enter key is chr (10), so if you want it to exit when the user clicks or presses enter, then add that in. Right now the enter key goes to the next line like on a word processor. I'll see if you can do that on your own to make sure you understand. |
Author: | ans4 [ Sat Oct 28, 2006 2:30 pm ] | ||
Post subject: | |||
Thanks for the help. And to exit the program you could also use KEY_ENTER right? [/code]var ch : string (1) var a : string := "" var x, y, button : int Draw.FillBox (100, 100, 200, 150, 4) %<- here is my box loop if hasch then getch (ch) a += ch locate (1, 1) put a exit when ch = chr (10) end if Mouse.Where (x, y, button) exit when button not= 0 and x >= 100 and y >= 100 and x <= 200 and y <= 150 %Notice the numbers used here and the numbers for drawing the box end loop
|
Author: | richcash [ Sat Oct 28, 2006 2:39 pm ] |
Post subject: | |
Yap, KEY_ENTER can be used instead of chr (10). Nice code, I think you understand. |