KeyboardLayoutMap

这是 实验性技术
检查 浏览器兼容性表格 在生产中使用这之前。

KeyboardLayoutMap interface of the the Keyboard API is a map-like object with functions for retrieving the string associated with specific physical keys. A list of valid keys is found in the UI Events KeyboardEvent code Values specification.

特性

KeyboardLayoutMap.entries 只读
Returns an array of a given object's own enumerable property [key, value] pairs, in the same order as that provided by a for...in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).
KeyboardLayoutMap.keys 只读
Returns a new Array Iterator object that contains the keys for each index in the array.
KeyboardLayoutMap.size 只读
Returns the number of elements in the KeyboardLayoutMap 对象。
KeyboardLayoutMap.values 只读
Returns a new Array Iterator object that contains the values for each index in the KeyboardLayoutMap 对象。

方法

KeyboardLayoutMap.forEach() 只读
Executes a provided function once for each element of KeyboardLayoutMap .
KeyboardLayoutMap.get()
Returns the element with the given key from the KeyboardLayoutMap 对象。
KeyboardLayoutMap.has()
Returns a boolean indicating whether the KeyboardLayoutMap object has an element with the specified key.

范例

The following example demonstrates how to get the location- or layout-specific string associated with the key that corresponds to the 'W' key on an English QWERTY keyboard.

var keyboard = navigator.keyboard;
keyboard.getLayoutMap()
.then(keyboardLayoutMap => {
  var upKey = keyboardLayoutMap.get('KeyW');
  window.alert('Press ' + upKey + ' to move up.');
})
					

规范

规范 状态 Comment
Keyboard Map
The definition of 'KeyboardLayoutMap' in that specification.
编者草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
KeyboardLayoutMap
Chrome 69 Edge 79 Firefox No IE No Opera 55 Safari No WebView Android No Chrome Android No Firefox Android No Opera Android 48 Safari iOS No Samsung Internet Android No
entries
Chrome 69 Edge 79 Firefox No IE No Opera 56 Safari No WebView Android No Chrome Android No Firefox Android No Opera Android 48 Safari iOS No Samsung Internet Android No
forEach
Chrome 69 Edge 79 Firefox No IE No Opera 56 Safari No WebView Android No Chrome Android No Firefox Android No Opera Android 48 Safari iOS No Samsung Internet Android No
get
Chrome 69 Edge 79 Firefox No IE No Opera 56 Safari No WebView Android No Chrome Android No Firefox Android No Opera Android 48 Safari iOS No Samsung Internet Android No
has
Chrome 69 Edge 79 Firefox No IE No Opera 56 Safari No WebView Android No Chrome Android No Firefox Android No Opera Android 48 Safari iOS No Samsung Internet Android No
keys
Chrome 69 Edge 79 Firefox No IE No Opera 56 Safari No WebView Android No Chrome Android No Firefox Android No Opera Android 48 Safari iOS No Samsung Internet Android No
size
Chrome 69 Edge 79 Firefox No IE No Opera 56 Safari No WebView Android No Chrome Android No Firefox Android No Opera Android No Safari iOS No Samsung Internet Android No
values
Chrome 69 Edge 79 Firefox No IE No Opera 56 Safari No WebView Android No Chrome Android No Firefox Android No Opera Android 48 Safari iOS No Samsung Internet Android No

图例

完整支持
完整支持
不支持
不支持
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。