# Set variable if none WASD keys are pressed

**URL:** <https://forums.unrealengine.com/t/set-variable-if-none-wasd-keys-are-pressed/449815>\
**Category:** Blueprint\
**Tags:** add-variable, unreal-engine, UE4, Blueprint, question, key-bind\
**Created:** [May 29, 2019, 8:11pm UTC](https://forums.unrealengine.com/t/set-variable-if-none-wasd-keys-are-pressed/449815 "2019-05-29T20:11:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zghenzi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zghenzi](https://forums.unrealengine.com/u/zghenzi)\
**Post date:** [May 29, 2019, 8:11pm UTC](https://forums.unrealengine.com/t/set-variable-if-none-wasd-keys-are-pressed/449815/1 "2019-05-29T20:11:33Z")

</div>

Hi,

What the code below does is adding **FallingLateralFriction when one of the WASD keys is released** , but what I need is to add **FallingLateralFriction** when none of the **WASD keys are pressed at the same time** - so I need it to detect if any of the WASD keys are being inputed, if not, add **FallingLateralFriction**.

 ![278337-bp.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/b/0/db06730495fea77a7c3e8e9f1e84c0a554fccdd9.jpeg)

---

<div class="post-metadata">

**Author:** ![Arlyn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Arlyn](https://forums.unrealengine.com/u/Arlyn)\
**Post date:** [May 29, 2019, 9:33pm UTC](https://forums.unrealengine.com/t/set-variable-if-none-wasd-keys-are-pressed/449815/2 "2019-05-29T21:33:44Z")

</div>

Hello,

Interesting problem you have here.

Here is an idea:

1. Create a Boolean Variable for each key input and set it as true or false depending on whether or not it has been released.
2. Then, off of Event Tick, create a branch that where it takes an OR operator and you input each of the Boolean Variables for the key inputs. That way if one of the Key Inputs is true, the branch will go true. If all are false, the branch will go false.
3. Hook up your Lateral Friction Falling Code
4. (Optional) On Event Begin play, Use a [Set Tick Interval](https://api.unrealengine.com/INT/BlueprintAPI/Utilities/SetActorTickInterval/index.html) node and the value at .1 (1/10th of a second). That should help optimize the tick function if you’re worried about it running every frame.

I hope this helps and let me know if this makes sense!

---

<div class="post-metadata">

**Author:** ![zghenzi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zghenzi](https://forums.unrealengine.com/u/zghenzi)\
**Post date:** [May 29, 2019, 9:47pm UTC](https://forums.unrealengine.com/t/set-variable-if-none-wasd-keys-are-pressed/449815/3 "2019-05-29T21:47:06Z")

</div>

Hey, thanks for the reply. Do you mean something like this?

 ![278342-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/8/4/c84eed69a21a23cf1e64be9f2f4da0f0da88933a.png)

I can’t reproduce anything with this, guess I’m doing something wrong - however, I found a workaround but still it isn’t perfect:

 ![278343-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/0/4/e046d9e091857e6a47f9337cd36ee05daecff010.png)

I think the main problem is the **Released** state because it only reads it if there were a previous **Pressed** state

---

<div class="post-metadata">

**Author:** ![Arlyn](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Arlyn](https://forums.unrealengine.com/u/Arlyn)\
**Post date:** [May 29, 2019, 10:01pm UTC](https://forums.unrealengine.com/t/set-variable-if-none-wasd-keys-are-pressed/449815/4 "2019-05-29T22:01:13Z")

</div>

Not quite! It doesn’t look like the values are ever set to true so it will always trigger false. Also try to use positives as your Boolean values. Having it as Not Pressed is confusing (at least to me :))

Lets do W for an example:  
Create a Boolean variable called W Pressed.  
From the W Event, Set the W is Pressed Variable to True off the Pressed Execution Pin. Then set the W is Press Variable to false off the Released Execution Pin.

I think you’ll want to use Get Variables rather than pulling the Pins directly from the Set Variables as well.

I’ll try to throw this into an example BP when I get home tonight so its a bit more clear.

---

<div class="post-metadata">

**Author:** ![zghenzi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zghenzi](https://forums.unrealengine.com/u/zghenzi)\
**Post date:** [May 30, 2019, 6:05pm UTC](https://forums.unrealengine.com/t/set-variable-if-none-wasd-keys-are-pressed/449815/5 "2019-05-30T18:05:31Z")

</div>

Hi, I’ve done it like this:

 ![278439-bp1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/0/d/60d19203c8a4cad1bc1908a4b0f18ec9acbffe62.jpeg)

Is there a way to print it like this? Why can’t I use one duplicate event that is already declared in other code, like “Event OnLanded” or “Event BeginPlay”?

 ![278440-bp2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/f/5/6f51591eee3ec7df86ec5ba7b6296ba576a936de.jpeg)

Thanks!
