Namespace: SpawnDev.SpawnJS.JSObjects
Source: JSObjects/KeyLocation.cs
The following constants identify which part of the keyboard the key event originates from.
| Name | JSON Value | Description |
|---|---|---|
DomKeyLocationStandard |
The key described by the event is not identified as being located in a particular area of the keyboard. https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#constants | |
DomKeyLocationLeft |
The key is one which may exist in multiple locations on the keyboard and, in this instance, is on the left side of the keyboard. https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#constants | |
DomKeyLocationRight |
The key is one which may exist in multiple positions on the keyboard and, in this case, is located on the right side of the keyboard. https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#constants | |
DomKeyLocationNumpad |
The key is located on the numeric keypad, or is a virtual key associated with the numeric keypad if there's more than one place the key could originate from. https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#constants |
| Property | Type | Access | Description |
|---|---|---|---|
KeyLocation |
enum |
get | The following constants identify which part of the keyboard the key event originates from. |
SpawnDev.SpawnJS Mapping Note: The JavaScript examples below show the standard Web API usage. In SpawnDev.SpawnJS, the same API is available with C# conventions:
- Properties and methods use PascalCase (e.g.,
readyStatebecomesReadyState)- Events use ActionEvent with
+=/-=(e.g.,addEventListener("click", fn)becomesOnClick += handler)- Async methods return
Task<T>instead ofPromise<T>- Objects should be disposed with
usingstatements- Access via
JS.Get<KeyLocation>(...)or constructornew KeyLocation(...)
document.addEventListener("keydown", (event) => {
const keyName = event.key;
if (keyName === "Control") {
// do not alert when only Control key is pressed.
return;
}
if (event.ctrlKey) {
// Even though event.key is not 'Control' (e.g., 'a' is pressed),
// event.ctrlKey may be true if Ctrl key is pressed at the same time.
alert(`Combination of ctrlKey + ${keyName}`);
} else {
alert(`Key pressed ${keyName}`);
}
});
document.addEventListener("keyup", (event) => {
const keyName = event.key;
// As the user releases the Ctrl key, the key is no longer active,
// so event.ctrlKey is false.
if (keyName === "Control") {
alert("Control key was released");
}
});