Welcome, Guest. Please login or register.
Did you miss your activation email?
October 20, 2014, 09:12:11 PM

Login with username, password and session length
Search:     Advanced search
* Home Help Search Calendar Links Login Register
+  Machsupport Forum
|-+  Mach Discussion
| |-+  Mach Screens
| | |-+  Flash Screens
| | | |-+  Flash problem
Pages: 1   Go Down
Print
Author Topic: Flash problem  (Read 2873 times)
0 Members and 1 Guest are viewing this topic.
ebidese
Holding

Offline Offline

Posts: 2


View Profile
« on: October 17, 2008, 06: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?

 Grin
Logged
zealous
Active Member

Offline Offline

Posts: 489


HI!


View Profile WWW
« Reply #1 on: October 17, 2008, 07: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:
Key.removeListener(key_Listener_Function);

Also you can remove the function as well:

Code:
///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:
///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:

<a href="http://alphagraphicdesigns.com/demo/KeyWatchMach.swf" target="_blank">http://alphagraphicdesigns.com/demo/KeyWatchMach.swf</a>
« Last Edit: October 17, 2008, 07:41:50 PM by zealous » Logged

zealous
Active Member

Offline Offline

Posts: 489


HI!


View Profile WWW
« Reply #2 on: October 21, 2008, 03: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:
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);
Logged

Pages: 1   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!