harmony 鸿蒙Shortcut Key Development

  • 2025-06-06
  • 浏览 (2)

Shortcut Key Development

When to Use

You can set the delay for starting an ability using the shortcut key. An example is to take a screenshot 5 seconds after the shortcut key is pressed.

Modules to Import

import { shortKey } from '@kit.InputKit';

Available APIs

The following table lists the common APIs provided by the shortKey module. For details, see ohos.multimodalInput.shortKey.

API Description
setKeyDownDuration(businessKey: string, delay: number, callback: AsyncCallback<void>): void Sets the delay for starting an ability using the shortcut key.

How to Develop

The following describes how to take a screenshot five seconds after the shortcut key is pressed.

import { shortKey } from '@kit.InputKit';
try {
  shortKey.setKeyDownDuration("screenshot", 500, (error) => {// Set the delay to 5 seconds (500 ms)
    if (error) {
      console.log(`Set key down duration failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
      return;
    }
    console.log(`Set key down duration success`);
  });
} catch (error) {
  console.log(`Set key down duration failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Input Kit (Multimodal Input)

harmony 鸿蒙Introduction to Input Kit

harmony 鸿蒙Combination Key Development

harmony 鸿蒙Input Device Development

harmony 鸿蒙Event Injection Development

harmony 鸿蒙Input Monitor Development

harmony 鸿蒙Event Interception Development (C/C++)

harmony 鸿蒙Event Listening Development (C/C++)

harmony 鸿蒙Mouse Pointer Development

0  赞