From 79a8afc81d7a38e4f2b9698903ad3e9618d6ae92 Mon Sep 17 00:00:00 2001 From: Jeff Posnick Date: Wed, 13 Apr 2016 15:41:59 -0400 Subject: [PATCH] Sample for KeyboardEvent.key --- keyboardevent-key-attribute/README.md | 5 +++++ keyboardevent-key-attribute/demo.js | 7 ++++++ keyboardevent-key-attribute/index.html | 31 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100755 keyboardevent-key-attribute/README.md create mode 100644 keyboardevent-key-attribute/demo.js create mode 100755 keyboardevent-key-attribute/index.html diff --git a/keyboardevent-key-attribute/README.md b/keyboardevent-key-attribute/README.md new file mode 100755 index 0000000..46de6fa --- /dev/null +++ b/keyboardevent-key-attribute/README.md @@ -0,0 +1,5 @@ +KeyboardEvent key Attribute Sample +=== +See https://googlechrome.github.io/samples/keyboardevent-key-attribute/index.html for a live demo. + +Learn more at https://www.chromestatus.com/feature/4748790720364544 diff --git a/keyboardevent-key-attribute/demo.js b/keyboardevent-key-attribute/demo.js new file mode 100644 index 0000000..09d1b47 --- /dev/null +++ b/keyboardevent-key-attribute/demo.js @@ -0,0 +1,7 @@ +window.addEventListener('keydown', function(event) { + if ('key' in event) { + ChromeSamples.log('KeyboardEvent.key:', event.key); + } else { + ChromeSamples.setStatus('KeyboardEvent.key is not supported.'); + } +}); diff --git a/keyboardevent-key-attribute/index.html b/keyboardevent-key-attribute/index.html new file mode 100755 index 0000000..d7af40b --- /dev/null +++ b/keyboardevent-key-attribute/index.html @@ -0,0 +1,31 @@ +--- +feature_name: KeyboardEvent key Attribute +chrome_version: 51 +feature_id: 4748790720364544 +--- + +

Background

+

+ The KeyboardEvent.key + attribute returns the string value of the key (or keys) pressed by the user to + generate a + KeyboardEvent. +

+ +

+ Special control keys that do not have a direct string representation are given + key values that can be found in + this chart. + For example, pressing the caps lock key will result in a key + value of "CapsLock". +

+ +{% capture initial_output_content %} +

+ The KeyboardEvent.key values for any keys you press on the + keyboard will be logged here. +

+{% endcapture %} +{% include output_helper.html initial_output_content=initial_output_content %} + +{% include js_snippet.html filename='demo.js' %}