1e41f4b71Sopenharmony_ci# Combination Key Development 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## When to Use 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciThe **inputConsumer** module provides capabilities such as subscribing to combination key events and setting the key shielding status. For example, if an application needs to implement a shortcut function using combination keys, you can listen for combination key events to serve that purpose. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci## Modules to Import 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci```js 10e41f4b71Sopenharmony_ciimport { inputConsumer } from '@kit.InputKit'; 11e41f4b71Sopenharmony_ci``` 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## Available APIs 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciThe following table lists the common APIs provided by the inputConsumer module. For details, see [ohos.multimodalInput.inputConsumer-sys](../../reference/apis-input-kit/js-apis-inputconsumer-sys.md) and [ohos.multimodalInput.inputConsumer](../../reference/apis-input-kit/js-apis-inputconsumer.md). 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci| API | Description| 18e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | -------------------------- | 19e41f4b71Sopenharmony_ci| on(type: 'key', keyOptions: KeyOptions, callback: Callback\<KeyOptions>): void | Enables listening for combination key events.| 20e41f4b71Sopenharmony_ci| off(type: 'key', keyOptions: KeyOptions, callback?: Callback\<KeyOptions>): void | Disables listening for combination key events.| 21e41f4b71Sopenharmony_ci| setShieldStatus(shieldMode: ShieldMode, isShield: boolean): void | Sets the key shielding status.| 22e41f4b71Sopenharmony_ci| getShieldStatus(shieldMode: ShieldMode): boolean | Checks whether key shielding is enabled.| 23e41f4b71Sopenharmony_ci| getAllSystemHotkeys(): Promise\<Array\<HotkeyOptions>> | Obtains all system combination keys.| 24e41f4b71Sopenharmony_ci| on(type: 'hotkeyChange', hotkeyOptions: HotkeyOptions, callback: Callback\<HotkeyOptions>): void | Enables listening for global combination key events.| 25e41f4b71Sopenharmony_ci| off(type: 'hotkeyChange', hotkeyOptions: HotkeyOptions, callback?: Callback\<HotkeyOptions>): void | Disables listening for global combination key events.| 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci## How to Develop 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ciWhen an application that uses specific combination keys is started, [on](../../reference/apis-input-kit/js-apis-inputconsumer-sys.md#inputconsumeron) is called to subscribe to combination key events. 30e41f4b71Sopenharmony_ciWhen the application is stopped, [off](../../reference/apis-input-kit/js-apis-inputconsumer-sys.md#inputconsumeroff) is called to unsubscribe from combination key events. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci```js 33e41f4b71Sopenharmony_cilet leftAltKey = 2045; 34e41f4b71Sopenharmony_cilet tabKey = 2049; 35e41f4b71Sopenharmony_cilet callback = (keyOptions: inputConsumer.KeyOptions) => { 36e41f4b71Sopenharmony_ci console.log(`keyOptions: ${JSON.stringify(keyOptions)}`); 37e41f4b71Sopenharmony_ci} 38e41f4b71Sopenharmony_ci// Start the application. 39e41f4b71Sopenharmony_cilet keyOption: inputConsumer.KeyOptions = {preKeys: [leftAltKey], finalKey: tabKey, isFinalKeyDown: true, finalKeyDownDuration: 0}; 40e41f4b71Sopenharmony_citry { 41e41f4b71Sopenharmony_ci inputConsumer.on("key", keyOption, callback);// Listen for combination key events. 42e41f4b71Sopenharmony_ci} catch (error) { 43e41f4b71Sopenharmony_ci console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 44e41f4b71Sopenharmony_ci} 45e41f4b71Sopenharmony_ci// Stop the application. 46e41f4b71Sopenharmony_citry { 47e41f4b71Sopenharmony_ci inputConsumer.off("key", keyOption, callback);// Disable listening for combination key events. 48e41f4b71Sopenharmony_ci console.log(`Unsubscribe success`); 49e41f4b71Sopenharmony_ci} catch (error) { 50e41f4b71Sopenharmony_ci console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 51e41f4b71Sopenharmony_ci} 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_cilet leftCtrlKey = 2072; 54e41f4b71Sopenharmony_cilet zKey = 2042; 55e41f4b71Sopenharmony_cilet hotkeyCallback = (hotkeyOptions: inputConsumer.HotkeyOptions) => { 56e41f4b71Sopenharmony_ci console.log(`keyOptions: ${JSON.stringify(hotkeyOptions)}`); 57e41f4b71Sopenharmony_ci} 58e41f4b71Sopenharmony_cilet hotkeyOption: inputConsumer.HotkeyOptions = {preKeys: [leftCtrlKey], finalKey: zKey, isRepeat: false}; 59e41f4b71Sopenharmony_ci// Before subscribing to global combination keys, obtain all system combination keys and check whether the combination keys to subscribe are on the system combination key list. 60e41f4b71Sopenharmony_ciinputConsumer.getAllSystemHotkeys().then((data: Array<inputConsumer.HotkeyOptions>) => {//: Obtain all system combination keys. 61e41f4b71Sopenharmony_ci console.log(`List of system hotkeys : ${JSON.stringify(data)}`); 62e41f4b71Sopenharmony_ci}); 63e41f4b71Sopenharmony_ci// Start the application. 64e41f4b71Sopenharmony_citry { 65e41f4b71Sopenharmony_ci inputConsumer.on("hotkeyChange", hotkeyOption, hotkeyCallback);// Subscribe to global combination keys. 66e41f4b71Sopenharmony_ci} catch (error) { 67e41f4b71Sopenharmony_ci console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 68e41f4b71Sopenharmony_ci} 69e41f4b71Sopenharmony_ci// Stop the application. 70e41f4b71Sopenharmony_citry { 71e41f4b71Sopenharmony_ci inputConsumer.off("hotkeyChange", hotkeyOption, hotkeyCallback);// Unsubscribe from global combination keys. 72e41f4b71Sopenharmony_ci console.log(`Unsubscribe success`); 73e41f4b71Sopenharmony_ci} catch (error) { 74e41f4b71Sopenharmony_ci console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 75e41f4b71Sopenharmony_ci} 76e41f4b71Sopenharmony_ci``` 77