Keyboard: phương thức getLayoutMap()

Khả dụng hạn chế

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Phương thức getLayoutMap() của giao diện Keyboard trả về một Promise phân giải với một phiên bản của KeyboardLayoutMap là đối tượng dạng map với các hàm để lấy các chuỗi liên kết với các phím vật lý cụ thể.

Cú pháp

js
getLayoutMap()

Tham số

Không có.

Giá trị trả về

Một Promise phân giải với một phiên bản của KeyboardLayoutMap.

Ngoại lệ

SecurityError DOMException

Được ném ra nếu cuộc gọi bị chặn bởi chính sách quyền.

Ví dụ

Ví dụ sau minh họa cách lấy chuỗi cụ thể theo vị trí hoặc bố cục liên kết với phím tương ứng với phím 'W' trên bàn phím QWERTY tiếng Anh.

js
const keyboard = navigator.keyboard;
keyboard.getLayoutMap().then((keyboardLayoutMap) => {
  const upKey = keyboardLayoutMap.get("KeyW");
  window.alert(`Press ${upKey} to move up.`);
});

Thông số kỹ thuật

Thông số kỹ thuật
Keyboard Map
# h-keyboard-getlayoutmap

Tương thích trình duyệt

Xem thêm