Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-31-2008, 02:30 PM   #1
Worlds heaviest Simian
Join Date: Apr 2008
Posts: 53
Default on (keyPress "<num1>")

I made a calculator the other day (in about 30 minutes ) and now I want to make it possible to use the num pad to enter numbers. I've used if Key.IsDown for the arrow keys but nothing else. So can someone tell me how to use the num pad for the calculator
TenTonApe is offline   Reply With Quote
Old 08-31-2008, 03:22 PM   #2
Senior Member
dialectric's Avatar
Join Date: May 2006
Location: USA
Posts: 628


You can use a key listener to get all pressed keys. The code below is an example. NumLock would have to be on, I think, for this method to work, otherwise you would have to use a case statement to direct the keycodes, since the output wouldn't have an ascii value.

- dialectric

PHP Code:
//key_listen_obj.as for use with keyboard actionscript

//create object
key_listen = new Object();
key_info = new Object();

//key listener
key_listen.onKeyDown = function(){
key_info.ref Key;
key_info.keycode Key.getCode();
key_info.ascii Key.getAscii();
key_info.string = (String.fromCharCode(key_info.ascii));
key_info.number Number(key_info.string);
/* use traces to test input */
        //trace ("the current key is : " +key_info.keycode)
        //trace ("the current key ascii is : " +key_info.ascii)

if ((key_info.keycode != 0) && (key_info.number != undefined)) {
// a valid key is pressed 
        } else {
dialectric is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
keyPress Function Not Responding David Heath ActionScript 2.0 10 12-03-2006 01:02 PM
Any way to allow one keypress OR another? nutlog ActionScript 2.0 1 12-02-2006 09:07 PM
on (keyPress "<Space>") is not working! mgcom ActionScript 2.0 4 08-18-2006 04:13 PM
Keypress....Sorry, I know it's probably been posted a bunch. crazylegsmurphy ActionScript 2.0 5 02-24-2005 10:51 PM
Script for ANY keypress OleN ActionScript 1.0 (and below) 1 11-30-2002 01:38 PM

All times are GMT. The time now is 02:44 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.