Microsoft Silverlight will reach end of support after October 2021. Learn more.

Occurs when a keyboard key is released while the Silverlight plug-in or a specific control has focus.

object KeyUp="eventhandlerFunction"  .../>
[token = ]object.AddEventListener("KeyUp", eventhandlerFunction)


AddEventListener Parameters



A token that is returned from the function, which you can optionally retain as a variable. If you intend to call RemoveEventListener to remove the handler, you will need this token.



The name of your event handler function as it is defined in script. When used as an AddEventListener parameter, quotation marks around the function name are not required. (See the "Remarks" section.)

Event Handler Parameters



The object that invoked the event.




keyEventArgs.Key: An integer value that represents the key that is up. This value is the portable Key code, which is not operating system-specific.

keyEventArgs.PlatformKeyCode: An integer value that represents the key that is up. This value is the non-portable key code, which is operating system-specific.

keyEventArgs.Shift: A Boolean value that determines whether the SHIFT key is down.

keyEventArgs.Ctrl: A Boolean value that determines whether the CTRL key is down.

keyEventArgs.Handled: A Boolean value that determines whether event routing should continue. (Silverlight 2)

keyEventArgs.Source: Reports the object that raised the event. (Silverlight 2)

Managed Equivalent




Handling keyboard events might vary between browsers. When you create an application that uses keyboard input, make sure to test the application in your target browsers.

You can also add handlers in script by using a quoted string for the event handler name, as follows:

object.AddEventListener("KeyUp", "eventhandlerFunction")

This syntax also returns a token. However, the token is not an absolute requirement for removing the handler in cases where the handler was added by using a quoted string. For details, see RemoveEventListener.

For a keyboard event to be received, the Silverlight plug-in or a specific control within it needs to have focus. Otherwise, the events are not generated. A Silverlight plug-in can gain focus by user actions such as clicking on or tabbing to the plug-in area. Alternatively, you can force focus to the Silverlight plug-in by calling the focus() method in the browser Document Object Model (DOM) when you handle the OnLoad event from instantiation script.

The KeyDown event always precedes a KeyUp event.

For more information on basic concepts, see Events Overview for Silverlight or Keyboard Support. Note that these topics are written primarily for users of the managed API, and may not have code examples or specific information that address the JavaScript API scenarios.

KeyUp is a bubbling event, so you can handle KeyUp on the control that received focus, or on any parent object (the parent object itself does not have to be focusable to receive the routed event).


The following XAML example shows a KeyUp event defined for the root Canvas object.


    Text="Display KeyUp event arguments" />


The following JavaScript example shows how to implement a KeyUp event handler function. In this case, the Silverlight version is displayed when the keystroke combination CTRL+V is detected.

// Set the TextBlock to display the key values.
function onKeyUp(sender, keyEventArgs)
    // Determine whether the keystroke combination CTRL+V was detected.
    if ((keyEventArgs.key == 51) && (keyEventArgs.ctrl == true))
       // Retrieve a reference to the plug-in.
       var plugin = sender.getHost();

       // Display whether the 1.0 version of Silverlight is supported.
       alert("Silverlight version: " + plugin.IsVersionSupported);

Applies To

Border (Silverlight 2)


Grid (Silverlight 2)

PasswordBox (Silverlight 2)

Popup (Silverlight 2)

StackPanel (Silverlight 2)

TextBox (Silverlight 2)

See Also