ctrl

Ctrl is input utility for flash target...
It contains of single singleton class called Ctrl

Setup

to use it just import it

import ctrl.Ctrl;

and you may save the instance to make shortcut

static var c : Ctrl = Ctrl.instance;

and you must call update function every the end of game loop to make it works

function tick()
{
    // some code
    c.update();
}

and that is the basic setup...
for complete like this

package ;

import haxe.Timer;

import ctrl.Ctrl;

class Main()
{
    static var c : Ctrl = Ctrl.instance;
    
    var timer : Timer;
    
    public function new()
    {
        timer = new Timer(10);
        timer.run = tick;
    }
    
    function tick()
    {
        // some code
        c.update();
    }
    
    static function main()
    {
        new Main();
    }
}

Keyboard Input

that is the basic...
and to key is down like this

if(c.isDown("S"))
{
    // do something if "S" key is down
}

there are 2 methods here...
- it will return true as long as you hold (use isDown)
- or it will return true just once, and then it false... (use isPressed)

so if you just want to once true, better use isPressed

the methods are same with the key is up too...

if the key is symbol key like ; or : (it is in one button)
you just can write

c.isDown(";");

it just works for the symbol that is pressed without shift.
so
c.isDown(":");

will not works

btw...

c.isDown("s");

and
c.isDown("S");

do the same behavior, so it's case-insensitive

for the special key such as space or enter or escape, you can write

c.isDown("SPaCe"); // (it's case-insensitive too)

if you want to know whether capsLock is turned on, or numLock is turned on, you can do this

c.capsLock;
c.numLock;

if you want to know what is the lastPressed key or lastReleased key, use this

c.lastPressed;
c.lastReleased;

It will be null if the key is not pressed just in time.

if you want to get char from user input, let say for name input, you can use

c.getChar();

it will format the input, so if the user pressed "s key" with shift, it will return "S", if pressed "enter key", it will return "\n", and so on.

if you want to get the history of key input, you can access

c.buffer;

it will give you an array of the last key input, the lastest is in the beginning of array.

to adjust buffer length set the

c.bufferLength = someint;

Mouse Input

to tell whether mouse in the stage or no

c.mouseLeave;

to tell mouse is down

if(c.mouseDown)
{
    // do something if mouse down
}

there are mousePressed, mouseUp, mouseReleased too...

to get mouseX, mouseY, and mouseWheel

c.mouseX;
c.mouseY;
c.mouseWheel;

I think that's all :p...

version #10289, modified 2011-03-10 16:11:35 by alijaya