# Reading from keyboard

**URL:** <https://forum.kirupa.com/t/reading-from-keyboard/23522>\
**Category:** Uncategorized\
**Created:** [June 19, 2003, 12:54am UTC](https://forum.kirupa.com/t/reading-from-keyboard/23522 "2003-06-19T00:54:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![abichap](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@abichap](https://forum.kirupa.com/u/abichap)\
**Post date:** [June 19, 2003, 12:54am UTC](https://forum.kirupa.com/t/reading-from-keyboard/23522/1 "2003-06-19T00:54:51Z")

</div>

How do I read a key from the keyboard and use that key to generate an animation? For example, I type 1 on the keyboard upon presssing the 1 it will trigger an animation?

---

<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:** [June 19, 2003, 1:00am UTC](https://forum.kirupa.com/t/reading-from-keyboard/23522/2 "2003-06-19T01:00:35Z")

</div>

try this:

```auto
createEmptyMovieClip("lstnr", ++depth);
Key.addListener(lstnr);
lstnr.onKeyDown = function() {
	if (Key.isDown(49)) {
		/*
		code goes here
		*/
	}
};

```

[edit]

Key object key codes:

> A: 65  
> B: 66  
> C: 67  
> D: 68  
> E: 69  
> F: 70  
> G: 71  
> H: 72  
> I: 73  
> J: 74  
> K: 75  
> L: 76  
> M: 77  
> N: 78  
> O: 79  
> P: 80  
> Q: 81  
> R: 82  
> S: 83  
> T: 84  
> U: 85  
> V: 86  
> W: 87  
> X: 88  
> Y: 89  
> Z: 90  
> 0: 48  
> 1: 49  
> 2: 50  
> 3: 51  
> 4: 52  
> 5: 53  
> 6: 54  
> 7: 55  
> 8: 56  
> 9: 57

---

<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:** [June 19, 2003, 1:04am UTC](https://forum.kirupa.com/t/reading-from-keyboard/23522/3 "2003-06-19T01:04:08Z")

</div>

[AS]  
on (keypress “1”){  
\_root.movieClip.gotoAndPlay(“whatever”);  
}  
[/AS]

---

<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:** [June 26, 2003, 7:57am UTC](https://forum.kirupa.com/t/reading-from-keyboard/23522/4 "2003-06-26T07:57:51Z")

</div>

i’m sorry i didn’t get the correct message through. what i meant was if a user type in number 1, the movie will display the binary number of 1. the key is i will not know what the user is going to type. so if the user type in number 8, it will display the binary of 8

---

<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:** [June 26, 2003, 9:27am UTC](https://forum.kirupa.com/t/reading-from-keyboard/23522/5 "2003-06-26T09:27:31Z")

</div>

```auto
this.onKeyDown = function() {
	var num = parseInt(String.fromCharCode(Key.getCode()));
	var bin = parseInt(num.toString(2));
	trace(bin);
};
Key.addListener(this);

```

---

<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:** [June 26, 2003, 9:57am UTC](https://forum.kirupa.com/t/reading-from-keyboard/23522/6 "2003-06-26T09:57:30Z")

</div>

i just realized that it doesn’t work if you use the numeric keypad…

```auto
this.onKeyDown = function() {
	var code = Key.getCode()>=96 ? Key.getCode()-48 : Key.getCode();
	var num = parseInt(String.fromCharCode(code));
	var bin = parseInt(num.toString(2));
	trace(bin);
};
Key.addListener(this);

```

problem solved. 😛

---

<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:** [June 27, 2003, 5:10am UTC](https://forum.kirupa.com/t/reading-from-keyboard/23522/7 "2003-06-27T05:10:06Z")

</div>

i now can get the binary display out liaoz but the problem is i want the binary display in the particular place where i want to dispaly but not in the output column. so now what can i do to do that? sorry. thanks
