Machsupport Forum

Mach Discussion => Mach Screens => Flash Screens => Topic started by: ebidese on October 17, 2008, 07:50:19 AM

Title: Flash problem
Post by: ebidese on October 17, 2008, 07:50:19 AM
Hello

I have a problem.

I need to run a code G with the function:

fscommand ( "Code", ' ... ')

but it should be performed when a key on the keyboard is pressed.

How can I do?

 ;D
Title: Re: Flash problem
Post by: zealous on October 17, 2008, 08:39:28 PM
This is how you look for keys.

HIT:
If you call on the code again it will keep creating Listener objects so if you do not want multiple key listeners make sure to remove it before calling it again.
To remove a "Key Listener just do:

Code: [Select]
Key.removeListener(key_Listener_Function);
Also you can remove the function as well:

Code: [Select]
///Remove one if there is one so they dont multiply////
delete key_Listener_Function;

Then just call on it again later if you want to turn it back on.

Listen for Enter key:

Code: [Select]
///Create an object////;
key_Listener_Function = Object();

///On key down...you can change this to keyup/down ect...///;
key_Listener_Function.onKeyDown = function() {


///Which key was pressed///;
trace(Key.getAscii());

if (Key.isDown(Key.ENTER)) {


///What you are looking for///;
trace("enter key pressed");

///Send to Mach////
fscommand("Code", 'X10 Y5.6 Z 5.6');

}
};

///add listener to wait for the key press//;
Key.addListener(key_Listener_Function);

Test it out below:

http://alphagraphicdesigns.com/demo/KeyWatchMach.swf
Title: Re: Flash problem
Post by: zealous on October 21, 2008, 04:29:21 PM
Notified when a key is pressed. To use onKeyDown, you must create a listener object.
You can then define a function for onKeyDown and use addListener() to register the listener with the Key object, as shown in the following example:


Code: [Select]
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {

    trace("DOWN -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));

};
keyListener.onKeyUp = function() {

    trace("UP -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));

};
Key.addListener(keyListener);