• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  @ohos.multimodalInput.shortKey (Shortcut Key)
2
3The **shortKey** module provides APIs to set the delay for starting an ability using a shortcut key. For example, you can set the delay to 3 seconds so that a screenshot is taken when you press and hold the shortcut key for 3 seconds.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> - The APIs provided by this module are system APIs.
9
10##  Modules to Import
11
12```
13import shortKey from '@ohos.multimodalInput.shortKey';
14```
15
16##  shortKey.setKeyDownDuration
17
18setKeyDownDuration(businessKey: string, delay: number, callback: AsyncCallback<void>): void
19
20Sets the delay for starting an ability using the shortcut key. This API uses an asynchronous callback to return the result.
21
22**System capability**: SystemCapability.MultimodalInput.Input.ShortKey
23
24**Parameters**
25
26| Name    | Type               | Mandatory| Description                                                        |
27| ---------- | ------------------- | ---- | ------------------------------------------------------------ |
28| businessKey| string              | Yes  | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.|
29| delay      | number              | Yes  | Delay for starting an ability using the shortcut key, in ms.|
30| callback   | AsyncCallback<void> | Yes  | Callback used to return the result.                                                  |
31
32**Example**
33
34```
35try {
36  shortKey.setKeyDownDuration("screenshot", 500, (error) => {
37    if (error) {
38      console.log(`Set key down duration failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
39      return;
40    }
41    console.log(`Set key down duration success`);
42  });
43} catch (error) {
44  console.log(`Set key down duration failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
45}
46```
47
48
49
50## shortKey.setKeyDownDuration
51
52setKeyDownDuration(businessKey: string, delay: number): Promise<void>
53
54Sets the delay for starting an ability using the shortcut key. This API uses a promise to return the result.
55
56**System capability**: SystemCapability.MultimodalInput.Input.ShortKey
57
58**Parameters**
59
60| Name    | Type  | Mandatory| Description                                                        |
61| ---------- | ------ | ---- | ------------------------------------------------------------ |
62| businessKey| string | Yes  | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.|
63| delay      | number | Yes  | Delay for starting an ability using the shortcut key, in ms.|
64
65**Return value**
66
67| Parameters         | Description         |
68| ------------- | ------------- |
69| Promise<void> | Promise used to return the result.|
70
71**Example**
72
73```
74try {
75  shortKey.setKeyDownDuration("screenshot", 500).then(() => {
76    console.log(`Set key down duration success`);
77  });
78} catch (error) {
79  console.log(`Set key down duration failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
80}
81```
82