
-----------------------------------
Aange10
Sun Dec 25, 2011 6:54 pm

Clicking Module
-----------------------------------
I absolutely hate Turing's built in clicking detection. The buttonmoved function is terrible. Honestly, its results feels random at best. It is probably me using it wrong, but I don't care. It's too complicated, and the documentation sucks. So I made my own.

It's VERY simple to use. Firstly, you need to know the the Turing Walkthrough has a fabulous the same folder as where you'll be using it. You have to name it "DetectClick.tu". Make sure it is .tu and not .t. (There are ways to import the module without doing this. However, I will not cover those ways as they are covered in the tutorial) Now, in the file you are using it in, at the top, on very FIRST line you need to type import DetectClick.

Whoo! You now have the module imported to your program! Now using it is the simple part. The module has two functions that output TRUE if a click has happened, and FALSE if a click has not happened. The syntax for using these functions are easy; here is an example:


import DetectClick
loop
    var mouseX, mouseY, mouseB : int
    Mouse.Where (mouseX, mouseY, mouseB)
     if DetectClick.Click (mouseB, "left") = true then
         put "You've clicked!"
     else
         put "You have not clicked."
    end if
end loop


The module's two function's syntax's are as followed:

Click (mouseState : int, buttonToCheck : string)
QuickClick (mouseState : int, buttonToCheck : string)

The accepted terms for buttonToCheck are "left", "right", "middle", "null" and "nill". Using any other string (NOT case sensitive) will result in an error, telling you your problem.
The difference between Click and QuickClick is that a QuickClick will only detect a click if they press and release the mouse within 500ms, while Click does not have that restriction.

* If you have trouble feel free to ask for help, but REFER to the tutorial on Modules before doing so.
Remmember to call the functions of the module you must put "DetectClick." before it.


Here is the Module:

unit

module DetectClick

    export QuickClick, Click
    
    var lTimer, mTimer, rTimer : int := 0
    var QlTimer, QmTimer, QrTimer : int := 0
    
    
    fcn QC (mb : int, state : int, var timer : int) : boolean
    
        if mb = state then

            % Detect if its the first click
            if timer = 0 then
                timer := Time.Elapsed ()
            end if

        else

            % Check mouse timer and see if < 500 ms has passed
            if Time.Elapsed () - timer 