# Take keyboard input within storyboard (Blend, WPF, C#)

**URL:** <https://forum.kirupa.com/t/take-keyboard-input-within-storyboard-blend-wpf-c/312021>\
**Category:** programming\
**Created:** [July 22, 2010, 6:08pm UTC](https://forum.kirupa.com/t/take-keyboard-input-within-storyboard-blend-wpf-c/312021 "2010-07-22T18:08:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yko](https://avatars.discourse-cdn.com/v4/letter/y/3ec8ea/32.png) [@Yko](https://forum.kirupa.com/u/Yko)\
**Post date:** [July 22, 2010, 6:08pm UTC](https://forum.kirupa.com/t/take-keyboard-input-within-storyboard-blend-wpf-c/312021/1 "2010-07-22T18:08:36Z")

</div>

Hi guys,

New here. Came across this site as I’m learning and the tutorials have been fabulous.

My question is, I wanted to take a keyboard input when a storyboard is running and with that input, stops that storyboard and jump to another one.

I am “fixing” someone elses code and the way these storyboards are implemented are as follows.  
There are states (in C#) such as STATE\_1, STATE\_2, etc…

When the app starts, when a person press PgDn, a MoveForward function is called which has a switch/case statement.  
switch(currentState)  
case STATE\_1 {do something}

In that STATE\_1, a storyboard is initialized and started.

For example:

```auto
Storyboard s = (Storyboard)Window.FindResource("StopWhenPressPgDn");
StopWhenPressPgDn.Begin(this, true);

```

So, if I press PgDn again, it calls the MoveForward function agains and jumps to the next storyboard without stopping the current one.

So, from the tutorial, I tried something like this from STATE\_1:

```auto
KeyDown += new System.Windows.Input.KeyEventHandler(Windscreen_KeyDown);

```

Then it creates this function for me:

```auto
private void Windscreen_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
        	// TODO: Add event handler implementation here.
			if(e.Key == System.Windows.Input.Key.Next)
			{
				// Kill the current storyboard and load the next one

			}
        }

```

But I am not sure how to pass the current storyboard to the event or object and stop it. The only way I know how to stop storyboard is via StoryboardName.Stop(this) and that Storyboard is initialized inside the MoveForward function which the Windscreen\_KeyDown does not have access to.

Thanks bunch!

Yko
