aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/api/keyboardevent/which/index.html
blob: 11e1e3e48e7e31b865af4781ccc920f6fa14a435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
title: event.which
slug: Web/API/KeyboardEvent/which
tags:
  - DOM
  - events
  - metodo
  - which
translation_of: Web/API/KeyboardEvent/which
---
<p>{{ ApiRef() }}</p>
<h3 id="Summary" name="Summary">Resumen</h3>
<p>Devuelve el <code>keyCode</code> de la tecla presionada, o el codigo del caracter (<code>charCode</code>) de la tecla alfanumerica presionada.</p>
<h3 id="Syntax" name="Syntax">Sintaxis</h3>
<pre class="eval"><em>var keyResult</em> = event.which;
</pre>
<p><code>keyResult</code> contiene el codigo numerico para una tecla en particular, dependiendo si la tecla presionada es alfanumerica o no-alfanumerica. Por favor mire <code><a href="/en/DOM/event.charCode" title="en/DOM/event.charCode">charCode</a></code> y <code><a href="/en/DOM/event.keyCode" title="en/DOM/event.keyCode">keyCode</a></code> para mas informacion.</p>
<h3 id="Example" name="Example">Ejemplo</h3>
<pre>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;charCode/keyCode/which example&lt;/title&gt;

&lt;script type="text/javascript"&gt;

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"
     );
}


&lt;/script&gt;
&lt;/head&gt;

&lt;body
 onkeypress="showKeyPress(event);"
 onkeydown="keyDown(event);"
&gt;

&lt;p&gt;Por favor presione cualquier tecla.&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<div class="note">
 <strong>Nota:</strong> El codigo de arriba falla en Firefox 9 debido al <a class="link-https" href="https://bugzilla.mozilla.org/show_bug.cgi?id=696020" title="onkeypress attribute on body no longer gets events happening on the window">bug 696020</a>.</div>
<h3 id="Specification" name="Specification">Especificacion</h3>
<p>No es parte de ninguna especificacion.</p>