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> 9> - The APIs provided by this module are system APIs. 10 11## Modules to Import 12 13```js 14import shortKey from '@ohos.multimodalInput.shortKey'; 15``` 16 17## shortKey.setKeyDownDuration 18 19setKeyDownDuration(businessKey: string, delay: number, callback: AsyncCallback<void>): void 20 21Sets the delay for starting an ability using shortcut keys. This API uses an asynchronous callback to return the result. 22 23**System capability**: SystemCapability.MultimodalInput.Input.ShortKey 24 25**Parameters** 26 27| Name | Type | Mandatory| Description | 28| ---------- | ------------------- | ---- | ------------------------------------------------------------ | 29| businessKey| string | Yes | Unique service ID registered on the multimodal side. It corresponds to **businessId** in the **ability_launch_config.json** file.| 30| delay | number | Yes | Delay for starting an ability using shortcut keys, in milliseconds. This field is invalid only when shortcut keys are used.| 31| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 32 33**Example** 34 35```js 36import shortKey from '@ohos.multimodalInput.shortKey'; 37try { 38 shortKey.setKeyDownDuration("screenshot", 500, (error) => { 39 if (error) { 40 console.log(`Set key down duration failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 41 return; 42 } 43 console.log(`Set key down duration success`); 44 }); 45} catch (error) { 46 console.log(`Set key down duration failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 47} 48``` 49 50## shortKey.setKeyDownDuration 51 52setKeyDownDuration(businessKey: string, delay: number): Promise<void> 53 54Sets the delay for starting an ability using shortcut keys. 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 shortcut keys, in milliseconds. This field is invalid only when shortcut keys are used.| 64 65**Return value** 66 67| Parameters | Description | 68| ------------- | ------------- | 69| Promise<void> | Promise that returns no value.| 70 71**Example** 72 73```js 74import shortKey from '@ohos.multimodalInput.shortKey'; 75try { 76 shortKey.setKeyDownDuration("screenshot", 500).then(() => { 77 console.log(`Set key down duration success`); 78 }); 79} catch (error) { 80 console.log(`Set key down duration failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 81} 82``` 83