# Disabling keys w/actionscript?

**URL:** <https://forum.kirupa.com/t/disabling-keys-w-actionscript/42956>\
**Category:** flash\
**Created:** [February 15, 2004, 4:07am UTC](https://forum.kirupa.com/t/disabling-keys-w-actionscript/42956 "2004-02-15T04:07:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GLHeX](https://avatars.discourse-cdn.com/v4/letter/g/f19dbf/32.png) [@GLHeX](https://forum.kirupa.com/u/GLHeX)\
**Post date:** [February 15, 2004, 4:07am UTC](https://forum.kirupa.com/t/disabling-keys-w-actionscript/42956/1 "2004-02-15T04:07:47Z")

</div>

Hey what’s up? Long time reader first time poster. =P

(This question pertains to a game I am making, but the question itself is about actionscript. Not game programming.)

Okay I’m making a game in which the player must use the num pad keys to toggle switches. Which is no sweat but theres a huge problem. That flipping numlock key. If it’s off the key codes change using Key.getCode(); or Key.getAscii();

So for example when the numlock is on 1 returns key code 97. But when numlock is off it returns 35 (for the key ‘End’).

Is there a way to disable or set the numlock key to on or ‘toggled’ when starting a flash movie?

Any ideas/help would be appreciated. Thanks alot. :cap:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 16, 2004, 10:42pm UTC](https://forum.kirupa.com/t/disabling-keys-w-actionscript/42956/2 "2004-02-16T22:42:24Z")

</div>

why not tell the player to activate numlock before playing?  
like this the attached file 😃

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 16, 2004, 10:51pm UTC](https://forum.kirupa.com/t/disabling-keys-w-actionscript/42956/3 "2004-02-16T22:51:56Z")

</div>

Hahaha! Sounds like a good solution to me.

- Thanks for the idea flash4food.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 16, 2004, 11:41pm UTC](https://forum.kirupa.com/t/disabling-keys-w-actionscript/42956/4 "2004-02-16T23:41:44Z")

</div>

I like flash4food’s solution, which just _works_.

Just wanted to mention that keystroke handling is an excellent time to  
be using the **switch** statement, which is more efficient than a bunch of **if** s.

```auto

switch (Key.getCode()) 
{

case 97:
case 35:
     // do something
     break;

case 98:
case 36:
     // do something else
     break;

default:
     trace("What kinda krazy keys are you pressing, homestar?");
}

```
