1e41f4b71Sopenharmony_ci# @ohos.multimodalInput.inputConsumer (Input Consumer)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **inputConsumer** module implements listening for combination key events.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> - The initial APIs of this module are supported since API version 13. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Modules to Import
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci```js
14e41f4b71Sopenharmony_ciimport { inputConsumer } from '@kit.InputKit';
15e41f4b71Sopenharmony_ci```
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci## HotkeyOptions<sup>13+</sup>
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciDefines shortcut key options.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.InputConsumer
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci| Name       | Type  | Readable  | Writable  | Description     |
24e41f4b71Sopenharmony_ci| --------- | ------ | ------- | ------- | ------- |
25e41f4b71Sopenharmony_ci| preKeys   | Array&lt;number&gt; | Yes     | No     | Modifier key set. The number of modifier keys is [1, 2]. There is no requirement on the sequence of modifier keys.<br>For example, in **Ctrl+Shift+Esc**, **Ctrl** and **Shift** are modifier keys.|
26e41f4b71Sopenharmony_ci| finalKey  | number  | Yes     | No     | Modified key.<br>For example, in **Ctrl+Shift+Esc**, **Esc** is the modified key.|
27e41f4b71Sopenharmony_ci| isRepeat  | boolean  | Yes     | No     | Whether to report repeated key events. The value **true** means to report repeated key events, and the value **false** means the opposite. The default value is **true**.|
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci## inputConsumer.getAllSystemHotkeys<sup>13+</sup>
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_cigetAllSystemHotkeys(): Promise&lt;Array&lt;HotkeyOptions&gt;&gt;
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ciObtains all system shortcut keys. This API uses a promise to return the result.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.InputConsumer
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci**Return value**
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci| Parameter        |  Description                                      |
40e41f4b71Sopenharmony_ci| ---------- |  ---------------------------------------- |
41e41f4b71Sopenharmony_ci| Promise&lt;Array&lt;HotkeyOptions&gt;&gt;                    | Promise used to return the list of all system shortcut keys.|
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci**Example**
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci```js
46e41f4b71Sopenharmony_ciinputConsumer.getAllSystemHotkeys().then((data: Array<inputConsumer.HotkeyOptions>) => {
47e41f4b71Sopenharmony_ci  console.log(`List of system hotkeys : ${JSON.stringify(data)}`);
48e41f4b71Sopenharmony_ci});
49e41f4b71Sopenharmony_ci```
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci## inputConsumer.on<sup>13+</sup>
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_cion(type: 'hotkeyChange', hotkeyOptions: HotkeyOptions, callback: Callback&lt;HotkeyOptions&gt;): void
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ciEnables listening for global combination key events. This API uses an asynchronous callback to return the combination key data when a combination key event that meets the specified condition occurs.
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.InputConsumer
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci**Parameters**
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci| Name        | Type                        | Mandatory  | Description                                      |
62e41f4b71Sopenharmony_ci| ---------- | -------------------------- | ---- | ---------- |
63e41f4b71Sopenharmony_ci| type       | string                     | Yes   | Event type. This parameter has a fixed value of **hotkeyChange**.                  |
64e41f4b71Sopenharmony_ci| hotkeyOptions | [HotkeyOptions](#hotkeyoptions13)  | Yes   | Shortcut key options.                |
65e41f4b71Sopenharmony_ci| callback   | Callback&lt;HotkeyOptions&gt; | Yes   | Callback used to return the combination key data when a global combination key event that meets the specified condition occurs.|
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci**Example**
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci```js
70e41f4b71Sopenharmony_cilet leftCtrlKey = 2072;
71e41f4b71Sopenharmony_cilet zKey = 2042;
72e41f4b71Sopenharmony_cilet hotkeyOptions: inputConsumer.HotkeyOptions = {
73e41f4b71Sopenharmony_ci  preKeys: [ leftCtrlKey ],
74e41f4b71Sopenharmony_ci  finalKey: zKey,
75e41f4b71Sopenharmony_ci  isRepeat: true
76e41f4b71Sopenharmony_ci};
77e41f4b71Sopenharmony_cilet hotkeyCallback = (hotkeyOptions: inputConsumer.HotkeyOptions) => {
78e41f4b71Sopenharmony_ci  console.log(`hotkeyOptions: ${JSON.stringify(hotkeyOptions)}`);
79e41f4b71Sopenharmony_ci}
80e41f4b71Sopenharmony_citry {
81e41f4b71Sopenharmony_ci  inputConsumer.on("hotkeyChange", hotkeyOptions, hotkeyCallback);
82e41f4b71Sopenharmony_ci} catch (error) {
83e41f4b71Sopenharmony_ci  console.log(`Subscribe failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
84e41f4b71Sopenharmony_ci}
85e41f4b71Sopenharmony_ci```
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci## inputConsumer.off<sup>13+</sup>
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_cioff(type: 'hotkeyChange', hotkeyOptions: HotkeyOptions, callback?: Callback&lt;HotkeyOptions&gt;): void
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ciDisables listening for global combination key events. 
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci**System capability**: SystemCapability.MultimodalInput.Input.InputConsumer
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci**Parameters**
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci| Name        | Type                        | Mandatory  | Description                             |
98e41f4b71Sopenharmony_ci| ---------- | -------------------------- | ---- | ---------- |
99e41f4b71Sopenharmony_ci| type       | string                     | Yes   | Event type. This parameter has a fixed value of **hotkeyChange**.       |
100e41f4b71Sopenharmony_ci| hotkeyOptions | [HotkeyOptions](#hotkeyoptions13)  | Yes   | Shortcut key options.            |
101e41f4b71Sopenharmony_ci| callback   | Callback&lt;HotkeyOptions&gt; | No   | Callback to unregister. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.|
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci**Example**
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci```js
106e41f4b71Sopenharmony_cilet leftCtrlKey = 2072;
107e41f4b71Sopenharmony_cilet zKey = 2042;
108e41f4b71Sopenharmony_ci// Disable listening for a single callback.
109e41f4b71Sopenharmony_cilet hotkeyCallback = (hotkeyOptions: inputConsumer.HotkeyOptions) => {
110e41f4b71Sopenharmony_ci  console.log(`hotkeyOptions: ${JSON.stringify(hotkeyOptions)}`);
111e41f4b71Sopenharmony_ci}
112e41f4b71Sopenharmony_cilet hotkeyOption: inputConsumer.HotkeyOptions = {preKeys: [leftCtrlKey], finalKey: zKey, isRepeat: true};
113e41f4b71Sopenharmony_citry {
114e41f4b71Sopenharmony_ci  inputConsumer.on("hotkeyChange", hotkeyOption, hotkeyCallback);
115e41f4b71Sopenharmony_ci  inputConsumer.off("hotkeyChange", hotkeyOption, hotkeyCallback);
116e41f4b71Sopenharmony_ci  console.log(`Unsubscribe success`);
117e41f4b71Sopenharmony_ci} catch (error) {
118e41f4b71Sopenharmony_ci  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
119e41f4b71Sopenharmony_ci}
120e41f4b71Sopenharmony_ci```
121e41f4b71Sopenharmony_ci```js
122e41f4b71Sopenharmony_cilet leftCtrlKey = 2072;
123e41f4b71Sopenharmony_cilet zKey = 2042;
124e41f4b71Sopenharmony_ci// Disable listening for all callbacks.
125e41f4b71Sopenharmony_cilet hotkeyCallback = (hotkeyOptions: inputConsumer.HotkeyOptions) => {
126e41f4b71Sopenharmony_ci  console.log(`hotkeyOptions: ${JSON.stringify(hotkeyOptions)}`);
127e41f4b71Sopenharmony_ci}
128e41f4b71Sopenharmony_cilet hotkeyOption: inputConsumer.HotkeyOptions = {preKeys: [leftCtrlKey], finalKey: zKey, isRepeat: true};
129e41f4b71Sopenharmony_citry {
130e41f4b71Sopenharmony_ci  inputConsumer.on("hotkeyChange", hotkeyOption, hotkeyCallback);
131e41f4b71Sopenharmony_ci  inputConsumer.off("hotkeyChange", hotkeyOption);
132e41f4b71Sopenharmony_ci  console.log(`Unsubscribe success`);
133e41f4b71Sopenharmony_ci} catch (error) {
134e41f4b71Sopenharmony_ci  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
135e41f4b71Sopenharmony_ci}
136e41f4b71Sopenharmony_ci```
137