openharmony 鸿蒙 shortkey-guidelines-sys

2026-08-25 浏览 (1)

Preset Global Hotkey Development (for System Applications Only)

When to Use

You can use the preset global hotkeys to set the delay time for starting an ability. An example is to take a screenshot 5 seconds after the hotkey is pressed.

Modules to Import

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

Available APIs

The following table lists common APIs for event injection. For details, see @ohos.multimodalInput.shortKey (Preset Global Shortcut Keys) (System API).

APIDescription
setKeyDownDuration(businessKey: string, delay: number, callback: AsyncCallback<void>): voidSets the delay for starting an ability using the hotkey.

How to Develop

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

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

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text()
        .onClick(() => {
          try {
            shortKey.setKeyDownDuration("screenshot", 500, (error: BusinessError) => { // Set the delay to 5 seconds (500 ms).
              if (error) {
                console.error(`Set key down duration failed, error: ${JSON.stringify(error, ["code", "message"])}`);
                return;
              }
              console.info(`Set key down duration success`);
            });
          } catch (error) {
            console.error(`Set key down duration failed, error: ${JSON.stringify(error, ["code", "message"])}`);
          }
        })
    }
  }
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 keypressed-guidelines

openharmony 鸿蒙 inputconsumer-guidelines-sys

openharmony 鸿蒙 Readme-EN

openharmony 鸿蒙 inputeventclient-guidelines-sys

openharmony 鸿蒙 inputdevice-guidelines

openharmony 鸿蒙 interceptor-guidelines

openharmony 鸿蒙 pointerstyle-guidelines

openharmony 鸿蒙 input-overview

openharmony 鸿蒙 inputmonitor-guidelines-sys

openharmony 鸿蒙 monitor-guidelines

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/1mABTSpM