Namespace: SpawnDev.SpawnJS.JSObjects
Source: JSObjects/MouseButton.cs
MDN Reference: MouseButton on MDN
A number representing a given button https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button#value
| Name | JSON Value | Description |
|---|---|---|
PrimaryButton |
Primary button (usually the left button) | |
AuxiliaryButton |
Auxiliary button (usually the mouse wheel button or middle button) | |
SecondaryButton |
Secondary button (usually the right button) | |
FourthButton |
4th button (typically the "Browser Back" button) | |
FifthButton |
5th button (typically the "Browser Forward" button) |
| Property | Type | Access | Description |
|---|---|---|---|
MouseButton |
enum |
get | A number representing a given button https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button#value |
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<MouseButton>(...)or constructornew MouseButton(...)
const button = document.querySelector("#button");
const log = document.querySelector("#log");
button.addEventListener("mouseup", (e) => {
switch (e.button) {
case 0:
log.textContent = "Left button clicked.";
break;
case 1:
log.textContent = "Middle button clicked.";
break;
case 2:
log.textContent = "Right button clicked.";
break;
default:
log.textContent = `Unknown button code: ${e.button}`;
}
});
button.addEventListener("contextmenu", (e) => {
e.preventDefault();
});