ExperimentalExperimentalThe interaction fields. Must contain a keys array with at least one key.
The fields object must be JSON-serializable. Optionally include ui_element.custom_name
to provide a custom name for the UI element and event_properties.* entries.
See SendUserInteractionFields for details.
OptionalelementOrEvent: Event | ElementAn optional Element or KeyboardEvent used to auto-generate UI element fields
such as tag_name, id, detected_name, components, features, and properties.
When a KeyboardEvent is provided, the target element is resolved from the event.
If omitted, no UI element fields are included in the emitted event.
import { UserInteractionSpecialKey } from "@dynatrace/rum-javascript-sdk/types/rum-events";
// Basic key combination
dynatrace.interactions?.sendKeyPressEvent({
keys: [UserInteractionSpecialKey.CTRL, "S"]
});
// With an Element to capture UI element fields (tag_name, id, detected_name, components, etc.)
const button = document.getElementById("saveBtn");
dynatrace.interactions?.sendKeyPressEvent({
keys: [UserInteractionSpecialKey.ENTER]
}, button);
// With a native KeyboardEvent to resolve the target element
document.addEventListener("keydown", (event) => {
dynatrace.interactions?.sendKeyPressEvent({
keys: [UserInteractionSpecialKey.CTRL, "S"]
}, event);
});
// With a custom_name for the UI element
dynatrace.interactions?.sendKeyPressEvent({
keys: [UserInteractionSpecialKey.ESC],
"ui_element.custom_name": "CloseModal"
});
// With event properties for enrichment
dynatrace.interactions?.sendKeyPressEvent({
keys: [UserInteractionSpecialKey.CTRL, "S"],
"event_properties.context": "editor"
});
Sends a user interaction event for reporting custom keyboard shortcuts or key combinations that are not automatically detected. Only available if the User Interaction module is enabled.
Keys can be specified using Types.UserInteractionSpecialKey members or raw KeyboardEvent.key strings — raw values are normalized internally (e.g.
" "→"space","Control"→"ctrl"). The enum is optional but improves readability when constructing key arrays manually.