-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge KeyboardEvent/MouseEvent.which into UIEvent.which (#8751)
- Loading branch information
1 parent
9f1dd5d
commit 16e08ce
Showing
5 changed files
with
110 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
--- | ||
title: UIEvent.which | ||
slug: Web/API/UIEvent/which | ||
tags: | ||
- API | ||
- DOM | ||
- UIEvent | ||
- Property | ||
- Read-only | ||
- Reference | ||
browser-compat: api.UIEvent.which | ||
--- | ||
<div>{{ APIRef("DOM Events") }} {{Non-standard_header}}</div> | ||
|
||
<p>The <code><strong>UIEvent.which</strong></code> read-only property of the {{domxref("UIEvent")}} | ||
interface returns a number that indicates which button was pressed on the mouse, or the | ||
numeric <code>keyCode</code> or the character code (<code>charCode</code>) of the key | ||
pressed on the keyboard.</p> | ||
|
||
<h2 id="Syntax">Syntax</h2> | ||
|
||
<pre class="brush: js notranslate">var <em>result</em> = <em>event</em>.which; | ||
</pre> | ||
|
||
<h3 id="Return_value">Return value</h3> | ||
|
||
<h4 id="Return_value_KeyboardEvent">Return value for {{domxref("KeyboardEvent")}}</h4> | ||
|
||
<ul> | ||
<li><code>event.which</code> contains the numeric code for a particular key pressed, | ||
depending on whether an alphanumeric or non-alphanumeric key was pressed. Please see | ||
{{domxref("KeyboardEvent.charCode")}} and {{domxref("KeyboardEvent.keyCode")}} for | ||
more details.</li> | ||
</ul> | ||
|
||
<h4 id="Return_value_MouseEvent">Return value for {{domxref("MouseEvent")}} {{non-standard_inline}}</h4> | ||
|
||
<p>A number representing a given button:</p> | ||
|
||
<ul> | ||
<li><code>0</code>: No button</li> | ||
<li><code>1</code>: Left button</li> | ||
<li><code>2</code>: Middle button (if present)</li> | ||
<li><code>3</code>: Right button</li> | ||
</ul> | ||
|
||
<p>For a mouse configured for left-handed use, the button actions are reversed. In this | ||
case, the values are read from right to left.</p> | ||
|
||
<h2 id="Example">Example</h2> | ||
|
||
<pre class="brush: html"><html> | ||
<head> | ||
<title>charCode/keyCode/which example</title> | ||
|
||
<script type="text/javascript"> | ||
|
||
function showKeyPress(evt) { | ||
alert("onkeypress handler: \n" | ||
+ "keyCode property: " + evt.keyCode + "\n" | ||
+ "which property: " + evt.which + "\n" | ||
+ "charCode property: " + evt.charCode + "\n" | ||
+ "Character Key Pressed: " | ||
+ String.fromCharCode(evt.charCode) + "\n" | ||
); | ||
} | ||
|
||
function keyDown(evt) { | ||
alert("onkeydown handler: \n" | ||
+ "keyCode property: " + evt.keyCode + "\n" | ||
+ "which property: " + evt.which + "\n" | ||
); | ||
} | ||
|
||
</script> | ||
</head> | ||
|
||
<body | ||
onkeypress="showKeyPress(event);" | ||
onkeydown="keyDown(event);" | ||
> | ||
|
||
<p>Please press any key.</p> | ||
|
||
</body> | ||
</html> | ||
</pre> | ||
|
||
<h2 id="Specifications">Specifications</h2> | ||
|
||
{{Specifications}} | ||
|
||
<h2 id="Browser_compatibility">Browser compatibility</h2> | ||
|
||
<p>{{Compat}}</p> | ||
|
||
<h2 id="See_also">See also</h2> | ||
|
||
<ul> | ||
<li>{{domxref("KeyboardEvent")}}</li> | ||
<li>{{domxref("MouseEvent")}}</li> | ||
</ul> |