# Key.isDown... \[FMX\]

**URL:** <https://forum.kirupa.com/t/key-isdown-fmx/17284>\
**Category:** Uncategorized\
**Created:** [April 3, 2003, 12:06pm UTC](https://forum.kirupa.com/t/key-isdown-fmx/17284 "2003-04-03T12:06:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jongrace](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@jongrace](https://forum.kirupa.com/u/jongrace)\
**Post date:** [April 3, 2003, 12:06pm UTC](https://forum.kirupa.com/t/key-isdown-fmx/17284/1 "2003-04-03T12:06:09Z")

</div>

Hi all,

I am trying to use th following code to animte an object across the screen:

if (Key.isDown(Key.LEFT)) {

```
	speed++;
	clip._x -= speed/5;
	trace(speed);
}

```

speed is a variable with a set number.  
the effect is a sort of acceleration.

The problem I have is: How do I reset the speed after when the Key is not down?

---

<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 3, 2003, 12:56pm UTC](https://forum.kirupa.com/t/key-isdown-fmx/17284/2 "2003-04-03T12:56:33Z")

</div>

try this:  
if (Key.isDown(Key.LEFT)) {

speed++;  
clip.\_x -= speed/5;  
trace(speed);  
} **else {  
speed = 0  
}**

That should reset the speed!

---

<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 3, 2003, 2:28pm UTC](https://forum.kirupa.com/t/key-isdown-fmx/17284/3 "2003-04-03T14:28:24Z")

</div>

Hey thanks… it helped a bit but there was a conflict with the movie clip’s (enterFrame) call back of the function which constantly set the speed to 0.

I found another trick by creating a way to reset what other keys were setting the speed to:

if (Key.isDown(Key.RIGHT)) {  
if (leftSpeed \> 0){  
trace (“reset speed”);  
speed = 0;   
leftSpeed = 0;  
}  
speed++;  
clip.\_x += speed/5;  
rightSpeed = clip.\_x;  
trace(speed);  
if (speed\>=40) {  
speed = 40;  
}  
}

this works really well.  
Now i have to find something that does a kind a deceleration when the Key is released…
