1# Combination Key 2 3The input consumer module implements listening for key events. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> 9> - The APIs of this module are system APIs and cannot be called by third-party applications. 10 11 12## Modules to Import 13 14 15``` 16import inputConsumer from '@ohos.multimodalInput.inputConsumer'; 17``` 18 19 20## inputConsumer.on 21 22on(type: "key", keyOptions: KeyOptions, callback: Callback<KeyOptions>): void 23 24Enables listening for combination key events. When a combination key event that meets the specified conditions occurs, **KeyOptions** will be passed as an input parameter to **callback**. 25 26This is a system API. 27 28**Parameters** 29 30| Name| Type| Mandatory| Description| 31| -------- | -------- | -------- | -------- | 32| type | string | Yes| Type of the key input event to listen for. Only **key** is supported.| 33| keyOptions | [keyOptions](#keyoptions) | Yes| Key option, which specifies the condition for combination key input.| 34| callback | Callback<[keyOptions](#keyoptions)> | Yes| Callback used to return the result. When a key input event that meets the specified options occurs, **keyOptions** will be passed as an input parameter to **callback**.| 35 36**Example** 37 38``` 39let keyOptions = {preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0} 40let callback = function(keyOptions) { 41 console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey, 42 "isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration) 43} 44inputConsumer.on('key', keyOptions, callback); 45``` 46 47 48## inputConsumer.off 49 50off(type: "key", keyOptions: KeyOptions, callback: Callback<KeyOptions>): void 51 52Stops listening for combination key events. 53 54This is a system API. 55 56**System capability**: SystemCapability.MultimodalInput.Input.InputConsumer 57 58**Parameters** 59 60| Name| Type| Mandatory| Description| 61| -------- | -------- | -------- | -------- | 62| type | string | Yes| Type of the key input event to listen for. Only **key** is supported.| 63| keyOptions | [keyOptions](#keyoptions) | Yes| Key options passed to the key input event when listening starts.| 64| callback | Callback<[keyOptions](#keyoptions)> | Yes| Callback function passed to the key input event with the key option when listening starts.| 65 66**Example** 67 68``` 69let keyOptions = {preKeys: [], finalKey: 3, isFinalKeyDown: true, finalKeyDownDuration: 0} 70let callback = function(keyOptions) { 71 console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey, 72 "isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration) 73} 74inputConsumer.off('key', keyOptions, callback); 75``` 76 77 78## KeyOptions 79 80Defines the key options that are met when a combination key input event occurs. 81 82This is a system API. 83 84**System capability**: SystemCapability.MultimodalInput.Input.InputConsumer 85 86| Name| Type| Mandatory| Description| 87| -------- | -------- | -------- | -------- | 88| preKeys | Array | Yes| Array of precedent keys. This parameter can be left empty. There is no requirement on the sequence of precedent keys.| 89| finalKey | Number | Yes| Final key in the combination key. This parameter cannot be left blank.| 90| isFinalKeyDown | boolean | Yes| Indicates whether the final key is pressed or released. By default, the final key is pressed.| 91| finalKeyDownDuration | Number | Yes| Duration for pressing the final key. By default, there is no requirement on the duration.| 92