Skip to content

useKbd

把键名换成键帽上的符号。meta、ctrl、alt 会按当前系统换。

Installation

pnpm dlx @weme-ui/weme-ui add weme-ui/slim/use-kbd

Usage

import { useKbd } from '~/composables/use-kbd'

const { getKbdKey } = useKbd()
getKbdKey('meta_k')

Returns

挂载前 meta、ctrl、alt 是一个空格。挂载后 macOS 为 ⌘、⌃、⌥,其它系统为 Ctrl、Ctrl、Alt。

FieldType
macOSComputedRef<boolean>
userAgent 里有 Macintosh;
ComputedRef<boolean>
getKbdKey(value?: KbdKey | string) => string[]
查 kbdKeysMap。含 _ 时拆开再查。没有的键转成大写。空值返回 []
(value?: KbdKey | string) => string[]

kbdKeysMap

键名到符号。meta、ctrl、alt 在表里是空字符串,真正显示的符号见上面。

FieldDescription
meta—
—
ctrl—
—
alt—
—
win⊞
⊞
command⌘
⌘
shift⇧
⇧
control⌃
⌃
option⌥
⌥
enter↵
↵
delete⌦
⌦
backspace⌫
⌫
escape⎋
⎋
tab⇥
⇥
capsLock⇪
⇪
arrowUp↑
↑
arrowRight→
→
arrowDown↓
↓
arrowLeft←
←
pageup⇞
⇞
pagedown⇟
⇟
home↖
↖
end↘
↘

Types

KbdKey

keyof typeof kbdKeysMap

KbdKeySpecific

'meta' | 'alt' | 'ctrl'

Files

  • src/composables/use-kbd.ts