# One key at a time

**URL:** https://forum.kirupa.com/t/one-key-at-a-time/2078
**Category:** Uncategorized
**Created:** [April 30, 2002, 10:11am UTC](https://forum.kirupa.com/t/one-key-at-a-time/2078 "2002-04-30T10:11:08Z")
**Posts on this page:** 4
**Page:** 1

<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: [April 30, 2002, 10:11am UTC](https://forum.kirupa.com/t/one-key-at-a-time/2078/1 "2002-04-30T10:11:08Z")

</div>

Hi,

I’m trying to make a game where a stick figure’s movements are controlled by the keyboard. Pretty much everything works, but not exactly the way I want. Left, right, up, and down movements are controlled with the arrow keys. There are times where the stick figure can perform other actions by pressing other keys, like the spacebar. However, if I press an arrow key and spacebar, the figure will move AND perform the action attached to the spacebar. What I would like is a way to ‘lock out’ all other keys when any one key is down. Currently, I am using the following commands, in a function, to detect keys: if (Key.isDown (Key.LEFT)) etc…

Is there a method for locking out the other keys when one key is already pressed?

Thanks!

scigolf

---

<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: [April 30, 2002, 4:17pm UTC](https://forum.kirupa.com/t/one-key-at-a-time/2078/2 "2002-04-30T16:17:05Z")

</div>

do this:  
if(Key.isDown(Key.RIGHT)){  
// do the ‘right’ thing.  
} else if (Key.isDown(Key.LEFT)){  
// do the ‘left’ thing.  
} else if (Key.isDown(Key.UP)){  
// do the ‘up’ thing.  
} else if (Key.isDown(Key.DOWN)){  
// do the ‘down’ thing.  
} else if (Key.isDown(Key.SPACE)){  
// do the ‘space’ thing.  
}

by using ‘else if’ instead of 5 ‘if’ statements you are limiting the user to one keypress at a time.  
🙂  
jeremy

---

<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: [May 6, 2002, 10:03am UTC](https://forum.kirupa.com/t/one-key-at-a-time/2078/3 "2002-05-06T10:03:31Z")

</div>

Thank you!

scigolf

---

<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 6, 2002, 2:06pm UTC](https://forum.kirupa.com/t/one-key-at-a-time/2078/4 "2002-06-06T14:06:30Z")

</div>

Hey scigolf i tried to make a stick figure run while pressing right. But every thime i hold right it locks on the first frame of the movie clip. How do u make it so that if u hold right it will play the movie clip running while holding right down?
