• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  @ohos.multimodalInput.shortKey (系统预置全局快捷键)(系统接口)
2
3<!--Kit: Input Kit-->
4<!--Subsystem: MultimodalInput-->
5<!--Owner: @zhaoxueyuan-->
6<!--Designer: @hanruofei-->
7<!--Tester: @Lyuxin-->
8<!--Adviser: @Brilliantry_Rui-->
9
10通过本模块接口,可以设置快捷键拉起Ability的延迟时间,如设置长按快捷键3s后再截屏等。
11
12> **说明:**
13>
14> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
15>
16> - 本模块接口为系统接口。
17
18
19##  导入模块
20
21```js
22import { shortKey } from '@kit.InputKit';
23```
24
25##  shortKey.setKeyDownDuration
26
27setKeyDownDuration(businessKey: string, delay: number, callback: AsyncCallback&lt;void&gt;): void
28
29设置快捷键拉起Ability的延迟时间,使用Callback异步回调。
30
31**系统能力**:SystemCapability.MultimodalInput.Input.ShortKey
32
33**参数**:
34
35| 参数名     | 类型                | 必填 | 说明                                                         |
36| ---------- | ------------------- | ---- | ------------------------------------------------------------ |
37| businessKey| string              | 是   | 业务在多模侧注册的唯一标识,与ability_launch_config.json中的businessId对应。调用接口前自行查询。|
38| delay      | number              | 是   | 按下快捷键多长时间后拉起Ability,单位:ms,仅支持快捷键按下触发。 |
39| callback   | AsyncCallback&lt;void&gt; | 是   | 回调函数,设置成功时,err为undefined,否则为错误对象。 |
40
41**错误码**:
42
43以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
44
45| 错误码ID  | 错误信息             |
46| ---- | --------------------- |
47| 202  | SystemAPI permission error.  |
48| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
49
50**示例**:
51
52```js
53import { shortKey } from '@kit.InputKit';
54
55@Entry
56@Component
57struct Index {
58  build() {
59    RelativeContainer() {
60      Text()
61        .onClick(() => {
62          try {
63            shortKey.setKeyDownDuration("businessId", 500, (error) => {
64              if (error) {
65                console.error(`Set key down duration failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
66                return;
67              }
68              console.log(`Set key down duration success`);
69            });
70          } catch (error) {
71            console.error(`Set key down duration failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
72          }
73        })
74    }
75  }
76}
77```
78
79## shortKey.setKeyDownDuration
80
81setKeyDownDuration(businessKey: string, delay: number): Promise&lt;void&gt;
82
83设置快捷键拉起Ability的延迟时间,使用Promise异步回调。
84
85**系统能力**:SystemCapability.MultimodalInput.Input.ShortKey
86
87**参数**:
88
89| 参数名     | 类型   | 必填 | 说明                                                         |
90| ---------- | ------ | ---- | ------------------------------------------------------------ |
91| businessKey| string | 是   | 业务在多模侧注册的唯一标识,与ability_launch_config.json中的businessId对应。调用接口前自行查询。|
92| delay      | number | 是   | 按下快捷键多长时间后拉起Ability,单位:ms,仅支持快捷键按下触发。 |
93
94**返回值**:
95
96| 类型          | 说明          |
97| ------------- | ------------- |
98| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
99
100**错误码**:
101
102以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
103
104| 错误码ID  | 错误信息             |
105| ---- | --------------------- |
106| 202  | SystemAPI permission error.  |
107| 401  | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
108
109**示例**:
110
111```js
112import { shortKey } from '@kit.InputKit';
113
114@Entry
115@Component
116struct Index {
117  build() {
118    RelativeContainer() {
119      Text()
120        .onClick(() => {
121          try {
122            shortKey.setKeyDownDuration("businessId", 500).then(() => {
123              console.log(`Set key down duration success`);
124            });
125          } catch (error) {
126            console.error(`Set key down duration failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
127          }
128        })
129    }
130  }
131}
132```
133
134## FingerprintAction<sup>12+</sup>
135
136按键事件类型的枚举。
137
138**系统能力:** SystemCapability.MultimodalInput.Input.Core
139
140| 名称                 | 值          | 说明                |
141| ---------------------| ---------- | --------------------|
142| DOWN                 | 0 | 按下事件。           |
143| UP                   | 1 | 抬起事件。           |
144| SLIDE                | 2 | 滑动事件。           |
145| RETOUCH              | 3 | 滑动事件。           |
146| CLICK                | 4 | 点击事件。           |
147
148
149## FingerprintEvent<sup>12+</sup>
150
151按键事件的类型和相对按键的偏移位置。
152
153**系统能力:** SystemCapability.MultimodalInput.Input.Core
154
155| 名称      | 类型                                       |只读   | 可选  |说明                    |
156| --------  | ------------------------                  |-------|------ |--------               |
157| action    | [FingerprintAction](#fingerprintaction12)   | 否    |  否   |按键事件类型。           |
158| distanceX | number                                    | 否    |  否   |相对于光标位置的x轴偏移量(正数表示向右移动,负数表示向左移动)。 |
159| distanceY | number                                    | 否    |  否   |相对于光标位置的y轴偏移量(正数表示向上移动,负数表示向下移动)。 |
160