Occurs when the key is pressed while the plug-in has focus.
| XAML | object KeyDown="eventhandlerFunction" .../> |
| Scripting |
[token = ]object.AddEventListener("KeyDown", 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 down. This value is the portable Key code, which is not operating system-specific. keyEventArgs.PlatformKeyCode - an integer value that represents the key that is down. 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. |
Examples
The following XAML example shows a KeyDown event defined for the root Canvas object:
| XAML |
<Canvas
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
KeyDown="onKeyDown">
<TextBlock
x:Name="myTextBlock"
Text="Display KeyDown event arguments" />
</Canvas>
|
The following JavaScript example shows how to implement a KeyDown event handler function. In this case, the values of the keyEventArgs parameter are displayed for each KeyDown event:
| JavaScript |
// Set the TextBlock to display the key values.
function onKeyDown(sender, keyEventArgs)
{
var textBlock = sender.findName("myTextBlock");
// Concatenate the values of the KeyEventArgs parameter.
var msg = "key: " + keyEventArgs.key;
msg += " platformKeycode: " + keyEventArgs.platformKeyCode;
msg += " shift: " + keyEventArgs.shift;
msg += " ctrl: " + keyEventArgs.ctrl;
textBlock.text = msg;
}
|
Applies To
Canvas
See Also
Silverlight Keyboard Support
Silverlight Events
Key
KeyUp