aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/document/keydown_event
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/api/document/keydown_event
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/ja/web/api/document/keydown_event')
-rw-r--r--files/ja/web/api/document/keydown_event/index.html103
1 files changed, 103 insertions, 0 deletions
diff --git a/files/ja/web/api/document/keydown_event/index.html b/files/ja/web/api/document/keydown_event/index.html
new file mode 100644
index 0000000000..2ad42a2bad
--- /dev/null
+++ b/files/ja/web/api/document/keydown_event/index.html
@@ -0,0 +1,103 @@
+---
+title: 'Document: keydown イベント'
+slug: Web/API/Document/keydown_event
+tags:
+ - API
+ - DOM
+ - Document
+ - Event
+ - KeyboardEvent
+ - Reference
+ - keydown
+translation_of: Web/API/Document/keydown_event
+---
+<div>{{APIRef}}</div>
+
+<p><strong><code>keydown</code></strong> イベントは、キーが押されたときに発生します。</p>
+
+<p>{{domxref("Document/keypress_event", "keypress")}} イベントとは異なり、 <code>keydown</code> イベントはすべてのキーにおいて、文字が入力されるかどうかにかかわらず発生します。</p>
+
+<table class="properties">
+ <tbody>
+ <tr>
+ <th scope="row">バブリング</th>
+ <td>あり</td>
+ </tr>
+ <tr>
+ <th scope="row">キャンセル可能</th>
+ <td>はい</td>
+ </tr>
+ <tr>
+ <th scope="row">インターフェイス</th>
+ <td>{{domxref("KeyboardEvent")}}</td>
+ </tr>
+ <tr>
+ <th scope="row">イベントハンドラープロパティ</th>
+ <td>{{domxref("GlobalEventHandlers.onkeydown", "onkeydown")}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<p><code>keydown</code> および {{domxref("Document/keyup_event", "keyup")}} イベントが、どのキーが押されたのかを示すコードを提供するのに対し、 {{domxref("Document/keypress_event", "keypress")}} はどの<em>文字</em>が入力されたかを示します。例えば、小文字の "a" は <code>keydown</code> および <code>keyup</code> では65になるのに対し、 <code>keypress</code> では97になります。大文字の "A" はどのイベントでも65と報告されます。</p>
+
+<p>Firefox 65 から、 <code>keydown</code> および {{domxref("Document/keyup_event", "keyup")}} イベントは IME 入力中でも発生するようになり、 CJKT のユーザーのブラウザー間の互換性が向上しました ({{bug(354358)}}、またもっと有益な詳細は <a href="https://www.fxsitecompat.com/en-CA/docs/2018/keydown-and-keyup-events-are-now-fired-during-ime-composition/">keydown and keyup events are now fired during IME composition</a> を参照)。 IME 入力中のすべての <code>keydown</code> イベントを無視するには、次のようにします (229 は IME によって処理されたイベントに関連する <code>keyCode</code> の特殊な値のセットです)。</p>
+
+<pre class="brush: js">eventTarget.addEventListener("keydown", event =&gt; {
+ if (event.isComposing || event.keyCode === 229) {
+ return;
+ }
+ // 何かをする
+});
+</pre>
+
+<h2 id="Examples" name="Examples">例</h2>
+
+<h3 id="addEventListener_keydown_example" name="addEventListener_keydown_example">addEventListener keydown の例</h3>
+
+<p>この例はキーを押すたびに {{domxref("KeyboardEvent.code")}} の値をログ出力します。</p>
+
+<pre class="brush: html">&lt;p&gt;Focus the IFrame first (e.g. by clicking in it), then try pressing some keys.&lt;/p&gt;
+&lt;p id="log"&gt;&lt;/p&gt;</pre>
+
+<pre class="brush: js">document.addEventListener('keydown', logKey);
+
+function logKey(e) {
+ log.textContent += ` ${e.code}`;
+}</pre>
+
+<p>{{EmbedLiveSample("addEventListener_keydown_example")}}</p>
+
+<h3 id="onkeydown_equivalent" name="onkeydown_equivalent">onkeydown equivalent</h3>
+
+<pre class="brush: js">document.onkeydown = logKey;</pre>
+
+<h2 id="Specifications" name="Specifications">仕様書</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">仕様書</th>
+ <th scope="col">状態</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('UI Events', '#event-type-keydown')}}</td>
+ <td>{{Spec2('UI Events')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>
+
+<div class="hidden">このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> をチェックアウトしてプルリクエストを送信してください。</div>
+
+<p>{{Compat("api.Document.keydown_event")}}</p>
+
+<h2 id="See_also" name="See_also">関連情報</h2>
+
+<ul>
+ <li>{{domxref("Document/keypress_event", "keypress")}}</li>
+ <li>{{domxref("Document/keyup_event", "keyup")}}</li>
+ <li>{{domxref("Element")}} の {{domxref("Element/keydown_event", "keydown")}} イベント</li>
+</ul>