Skip to main content
Version: 22.9.0

Keyboard.down() 方法

¥Keyboard.down() method

调度 keydown 事件。

¥Dispatches a keydown event.

签名:

¥Signature:

class Keyboard {
abstract down(
key: KeyInput,
options?: Readonly<KeyDownOptions>
): Promise<void>;
}

参数

¥Parameters

范围

类型

描述

key

KeyInput

要按下的键的名称,例如 ArrowLeft。有关所有键名称的列表,请参阅 KeyInput

options

只读<KeyDownOptions>

(可选的)选项的对象。接受文本,如果指定,则使用该文本生成输入事件。接受命令,如果指定,则为键盘快捷键的命令,请参阅 Chromium 源代码 了解有效的命令名称。

Returns:

Promise<void>

备注

¥Remarks

如果 key 是单个字符,并且除了 Shift 之外没有按下任何修改键,也会生成 keypress/input 事件。可以指定 text 选项来强制生成输入事件。如果 key 是修饰键、ShiftMetaControlAlt,则后续按键将在该修饰键处于活动状态时发送。要释放修饰键,请使用 Keyboard.up()

¥If key is a single character and no modifier keys besides Shift are being held down, a keypress/input event will also generated. The text option can be specified to force an input event to be generated. If key is a modifier key, Shift, Meta, Control, or Alt, subsequent key presses will be sent with that modifier active. To release the modifier key, use Keyboard.up().

按下该键一次后,后续调用 Keyboard.down() 会将 repeat 设置为 true。要释放密钥,请使用 Keyboard.up()

¥After the key is pressed once, subsequent calls to Keyboard.down() will have repeat set to true. To release the key, use Keyboard.up().

修饰键确实会影响 Keyboard.down()。按住 Shift 将以大写形式键入文本。

¥Modifier keys DO influence Keyboard.down(). Holding down Shift will type the text in upper case.