KeyUp Event

Occurs when the key is released while the plug-in has focus.

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

AddEventListener Parameters

token

integer

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.

eventhandlerFunction

object

The name of your event handler function as it is defined in script. When used as an AddEventListener parameter, quotes around the function name are not required. See Remarks.

Event Handler Parameters

sender

object

Identifies the object that invoked the event.

keyEventArgs

object

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.

Remarks

The KeyUp event can only be defined for the root Canvas object of a Silverlight plug-in.

Note  For information on portability issues and which keystrokes the Web browser passes on the Silverlight content, see Silverlight Keyboard Support.

Note   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 using a quoted string for the event handler name:

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.

In order for a keyboard event to be received, the Silverlight plug-in needs to have focus; otherwise, the events are not generated. A Silverlight plug-in can gain focus by user actions, such as clicking on content in the plug-in, or by tabbing to it.

The keyDown event always precedes a KeyUp event.

Examples

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

XAML
<Canvas
  xmlns="https://schemas.microsoft.com/client/2007"
  xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
  KeyUp="onKeyUp">
  <TextBlock
    x:Name="myTextBlock"
    Text="Display KeyUp event arguments" />
</Canvas>

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 was detected:

JavaScript
// 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

Canvas

See Also

Silverlight Keyboard Support
Silverlight Events
Key
KeyDown