161847f8eSopenharmony_ci/*
261847f8eSopenharmony_ci * Copyright (C) 2021-2023 Huawei Device Co., Ltd.
361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
461847f8eSopenharmony_ci * you may not use this file except in compliance with the License.
561847f8eSopenharmony_ci * You may obtain a copy of the License at
661847f8eSopenharmony_ci *
761847f8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
861847f8eSopenharmony_ci *
961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and
1361847f8eSopenharmony_ci * limitations under the License.
1461847f8eSopenharmony_ci */
1561847f8eSopenharmony_ci
1661847f8eSopenharmony_ci/**
1761847f8eSopenharmony_ci * @file
1861847f8eSopenharmony_ci * @kit InputKit
1961847f8eSopenharmony_ci */
2061847f8eSopenharmony_ci
2161847f8eSopenharmony_ciimport { Callback } from './@ohos.base';
2261847f8eSopenharmony_ci
2361847f8eSopenharmony_ci/**
2461847f8eSopenharmony_ci * The event of key input management module is configured to subscribe and unsubscribe system keys.
2561847f8eSopenharmony_ci *
2661847f8eSopenharmony_ci * @namespace inputConsumer
2761847f8eSopenharmony_ci * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
2861847f8eSopenharmony_ci * @since 13
2961847f8eSopenharmony_ci */
3061847f8eSopenharmony_cideclare namespace inputConsumer {
3161847f8eSopenharmony_ci  /**
3261847f8eSopenharmony_ci   * Defines event of key that user want to subscribe or unsubscribe.
3361847f8eSopenharmony_ci   *
3461847f8eSopenharmony_ci   * @interface KeyOptions
3561847f8eSopenharmony_ci   * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
3661847f8eSopenharmony_ci   * @systemapi hide for inner use
3761847f8eSopenharmony_ci   * @since 8
3861847f8eSopenharmony_ci   */
3961847f8eSopenharmony_ci  interface KeyOptions {
4061847f8eSopenharmony_ci    /**
4161847f8eSopenharmony_ci     * The pre-keys that want to subscribe or unsubscribe.
4261847f8eSopenharmony_ci     *
4361847f8eSopenharmony_ci     * @type { Array<number> }
4461847f8eSopenharmony_ci     * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
4561847f8eSopenharmony_ci     * @systemapi hide for inner use
4661847f8eSopenharmony_ci     * @since 8
4761847f8eSopenharmony_ci     */
4861847f8eSopenharmony_ci    preKeys: Array<number>;
4961847f8eSopenharmony_ci
5061847f8eSopenharmony_ci    /**
5161847f8eSopenharmony_ci     * The post position key that want to subscribe or unsubscribe.
5261847f8eSopenharmony_ci     *
5361847f8eSopenharmony_ci     * @type { number }
5461847f8eSopenharmony_ci     * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
5561847f8eSopenharmony_ci     * @systemapi hide for inner use
5661847f8eSopenharmony_ci     * @since 8
5761847f8eSopenharmony_ci     */
5861847f8eSopenharmony_ci    finalKey: number;
5961847f8eSopenharmony_ci
6061847f8eSopenharmony_ci    /**
6161847f8eSopenharmony_ci     * The final key press down or up.
6261847f8eSopenharmony_ci     *
6361847f8eSopenharmony_ci     * @type { boolean }
6461847f8eSopenharmony_ci     * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
6561847f8eSopenharmony_ci     * @systemapi hide for inner use
6661847f8eSopenharmony_ci     * @since 8
6761847f8eSopenharmony_ci     */
6861847f8eSopenharmony_ci    isFinalKeyDown: boolean;
6961847f8eSopenharmony_ci
7061847f8eSopenharmony_ci    /**
7161847f8eSopenharmony_ci     * Duration of final key press.
7261847f8eSopenharmony_ci     *
7361847f8eSopenharmony_ci     * @type { number }
7461847f8eSopenharmony_ci     * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
7561847f8eSopenharmony_ci     * @systemapi hide for inner use
7661847f8eSopenharmony_ci     * @since 8
7761847f8eSopenharmony_ci     */
7861847f8eSopenharmony_ci    finalKeyDownDuration: number;
7961847f8eSopenharmony_ci
8061847f8eSopenharmony_ci    /**
8161847f8eSopenharmony_ci     * Whether to report repeated key events. By default, the value is true if it is left unspecified.
8261847f8eSopenharmony_ci     *
8361847f8eSopenharmony_ci     * @type { ?boolean }
8461847f8eSopenharmony_ci     * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
8561847f8eSopenharmony_ci     * @systemapi hide for inner use
8661847f8eSopenharmony_ci     * @since 13
8761847f8eSopenharmony_ci     */
8861847f8eSopenharmony_ci    isRepeat?: boolean;
8961847f8eSopenharmony_ci  }
9061847f8eSopenharmony_ci
9161847f8eSopenharmony_ci  /**
9261847f8eSopenharmony_ci   * Defines the shortcut key structure.
9361847f8eSopenharmony_ci   *
9461847f8eSopenharmony_ci   * @typedef HotkeyOptions
9561847f8eSopenharmony_ci   * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
9661847f8eSopenharmony_ci   * @since 13
9761847f8eSopenharmony_ci   */
9861847f8eSopenharmony_ci  interface HotkeyOptions {
9961847f8eSopenharmony_ci    /**
10061847f8eSopenharmony_ci     * Defines modifier keys. One or two modifier keys are supported.
10161847f8eSopenharmony_ci     *
10261847f8eSopenharmony_ci     * @type { Array<number> }
10361847f8eSopenharmony_ci     * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
10461847f8eSopenharmony_ci     * @since 13
10561847f8eSopenharmony_ci     */
10661847f8eSopenharmony_ci    preKeys: Array<number>;
10761847f8eSopenharmony_ci
10861847f8eSopenharmony_ci    /**
10961847f8eSopenharmony_ci     * Defines modified keys.
11061847f8eSopenharmony_ci     *
11161847f8eSopenharmony_ci     * @type { number }
11261847f8eSopenharmony_ci     * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
11361847f8eSopenharmony_ci     * @since 13
11461847f8eSopenharmony_ci     */
11561847f8eSopenharmony_ci    finalKey: number;
11661847f8eSopenharmony_ci
11761847f8eSopenharmony_ci    /**
11861847f8eSopenharmony_ci     * Whether to report repeated key events. By default, the value is true if it is left unspecified.
11961847f8eSopenharmony_ci     *
12061847f8eSopenharmony_ci     * @type { ?boolean }
12161847f8eSopenharmony_ci     * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
12261847f8eSopenharmony_ci     * @since 13
12361847f8eSopenharmony_ci     */
12461847f8eSopenharmony_ci    isRepeat?: boolean;
12561847f8eSopenharmony_ci  }
12661847f8eSopenharmony_ci
12761847f8eSopenharmony_ci  /**
12861847f8eSopenharmony_ci   * Shield mode.
12961847f8eSopenharmony_ci   *
13061847f8eSopenharmony_ci   * @enum { number }
13161847f8eSopenharmony_ci   * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
13261847f8eSopenharmony_ci   * @systemapi hide for inner use
13361847f8eSopenharmony_ci   * @since 11
13461847f8eSopenharmony_ci   */
13561847f8eSopenharmony_ci  enum ShieldMode {
13661847f8eSopenharmony_ci    /**
13761847f8eSopenharmony_ci     * Factory mode shield all key events
13861847f8eSopenharmony_ci     *
13961847f8eSopenharmony_ci     * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
14061847f8eSopenharmony_ci     * @systemapi hide for inner use
14161847f8eSopenharmony_ci     * @since 11
14261847f8eSopenharmony_ci     */
14361847f8eSopenharmony_ci    FACTORY_MODE
14461847f8eSopenharmony_ci  }
14561847f8eSopenharmony_ci
14661847f8eSopenharmony_ci  /**
14761847f8eSopenharmony_ci   * Subscribe system keys.
14861847f8eSopenharmony_ci   *
14961847f8eSopenharmony_ci   * @param { 'key' } type - type of the inputevent about input which is to be subscribed.
15061847f8eSopenharmony_ci   * @param { KeyOptions } keyOptions - the key events about input which is to be subscribed.
15161847f8eSopenharmony_ci   * @param { Callback<KeyOptions> } callback - callback function, receive reported data.
15261847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
15361847f8eSopenharmony_ci   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
15461847f8eSopenharmony_ci   * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
15561847f8eSopenharmony_ci   * @systemapi hide for inner use
15661847f8eSopenharmony_ci   * @since 8
15761847f8eSopenharmony_ci   */
15861847f8eSopenharmony_ci  /**
15961847f8eSopenharmony_ci   * Subscribe system keys.
16061847f8eSopenharmony_ci   *
16161847f8eSopenharmony_ci   * @param { 'key' } type - type of the inputevent about input which is to be subscribed.
16261847f8eSopenharmony_ci   * @param { KeyOptions } keyOptions - the key events about input which is to be subscribed.
16361847f8eSopenharmony_ci   * @param { Callback<KeyOptions> } callback - callback function, receive reported data.
16461847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Permission denied, non-system app called system api.
16561847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
16661847f8eSopenharmony_ci   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
16761847f8eSopenharmony_ci   * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
16861847f8eSopenharmony_ci   * @systemapi hide for inner use
16961847f8eSopenharmony_ci   * @since 12
17061847f8eSopenharmony_ci   */
17161847f8eSopenharmony_ci  function on(type: 'key', keyOptions: KeyOptions, callback: Callback<KeyOptions>): void;
17261847f8eSopenharmony_ci
17361847f8eSopenharmony_ci  /**
17461847f8eSopenharmony_ci   * Subscribe system keys.
17561847f8eSopenharmony_ci   *
17661847f8eSopenharmony_ci   * @param { 'key' } type - type of the inputevent about input which is to be subscribed.
17761847f8eSopenharmony_ci   * @param { KeyOptions } keyOptions - the key events about input which is to be subscribed.
17861847f8eSopenharmony_ci   * @param { Callback<KeyOptions> } callback - callback function, receive reported data.
17961847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
18061847f8eSopenharmony_ci   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
18161847f8eSopenharmony_ci   * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
18261847f8eSopenharmony_ci   * @systemapi hide for inner use
18361847f8eSopenharmony_ci   * @since 8
18461847f8eSopenharmony_ci   */
18561847f8eSopenharmony_ci  /**
18661847f8eSopenharmony_ci   * Subscribe system keys.
18761847f8eSopenharmony_ci   *
18861847f8eSopenharmony_ci   * @param { 'key' } type - type of the inputevent about input which is to be subscribed.
18961847f8eSopenharmony_ci   * @param { KeyOptions } keyOptions - the key events about input which is to be subscribed.
19061847f8eSopenharmony_ci   * @param { Callback<KeyOptions> } callback - callback function, receive reported data.
19161847f8eSopenharmony_ci   * @throws { BusinessError } 202 - Permission denied, non-system app called system api.
19261847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
19361847f8eSopenharmony_ci   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
19461847f8eSopenharmony_ci   * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
19561847f8eSopenharmony_ci   * @systemapi hide for inner use
19661847f8eSopenharmony_ci   * @since 12
19761847f8eSopenharmony_ci   */
19861847f8eSopenharmony_ci  function off(type: 'key', keyOptions: KeyOptions, callback?: Callback<KeyOptions>): void;
19961847f8eSopenharmony_ci
20061847f8eSopenharmony_ci  /**
20161847f8eSopenharmony_ci   * Sets whether shield key event interception, only support shield key event.
20261847f8eSopenharmony_ci   *
20361847f8eSopenharmony_ci   * @permission ohos.permission.INPUT_CONTROL_DISPATCHING
20461847f8eSopenharmony_ci   * @param { ShieldMode } shieldMode - According the shield mode select shield key event range.
20561847f8eSopenharmony_ci   * @param { boolean } isShield - Indicates whether control key event dispatch. The value <b>true</b> indicates
20661847f8eSopenharmony_ci   * all key events directly dispatch to window, if the value <b>false</b> indicates not shield shortcut key.
20761847f8eSopenharmony_ci   * @throws { BusinessError } 201 - Permission denied.
20861847f8eSopenharmony_ci   * @throws { BusinessError } 202 - SystemAPI permission error.
20961847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
21061847f8eSopenharmony_ci   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
21161847f8eSopenharmony_ci   * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
21261847f8eSopenharmony_ci   * @systemapi hide for inner use.
21361847f8eSopenharmony_ci   * @since 11
21461847f8eSopenharmony_ci   */
21561847f8eSopenharmony_ci  function setShieldStatus(shieldMode: ShieldMode, isShield: boolean): void;
21661847f8eSopenharmony_ci
21761847f8eSopenharmony_ci  /**
21861847f8eSopenharmony_ci   * Gets shield event interception status corresponding to shield mode
21961847f8eSopenharmony_ci   *
22061847f8eSopenharmony_ci   * @permission ohos.permission.INPUT_CONTROL_DISPATCHING
22161847f8eSopenharmony_ci   * @param { ShieldMode } shieldMode - According the shield mode select shield key event range.
22261847f8eSopenharmony_ci   * @returns { boolean } Returns true if shield event interception, returns false otherwise.
22361847f8eSopenharmony_ci   * @throws { BusinessError } 201 - Permission denied.
22461847f8eSopenharmony_ci   * @throws { BusinessError } 202 - SystemAPI permission error.
22561847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
22661847f8eSopenharmony_ci   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
22761847f8eSopenharmony_ci   * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
22861847f8eSopenharmony_ci   * @systemapi hide for inner use.
22961847f8eSopenharmony_ci   * @since 11
23061847f8eSopenharmony_ci   */
23161847f8eSopenharmony_ci  function getShieldStatus(shieldMode: ShieldMode): boolean;
23261847f8eSopenharmony_ci
23361847f8eSopenharmony_ci  /**
23461847f8eSopenharmony_ci   * Obtains all system hotkeys. This API uses a promise to return the result.
23561847f8eSopenharmony_ci   *
23661847f8eSopenharmony_ci   * @Returns { Promise<Array<HotkeyOptions>> } All system hotkeys.
23761847f8eSopenharmony_ci   * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
23861847f8eSopenharmony_ci   * @since 13
23961847f8eSopenharmony_ci   */
24061847f8eSopenharmony_ci  function getAllSystemHotkeys(): Promise<Array<HotkeyOptions>>;
24161847f8eSopenharmony_ci
24261847f8eSopenharmony_ci  /**
24361847f8eSopenharmony_ci   * Listening for hotkey event changes.
24461847f8eSopenharmony_ci   *
24561847f8eSopenharmony_ci   * @param { 'hotkeyChange' } type - Type of the hotkey events.
24661847f8eSopenharmony_ci   * @param { HotkeyOptions } hotkeyOptions - hotkey events.
24761847f8eSopenharmony_ci   * @param { Callback<HotkeyOptions> } callback - Callback used to return hotkey events.
24861847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
24961847f8eSopenharmony_ci   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
25061847f8eSopenharmony_ci   * @throws { BusinessError } 4200002 - The hotkey has been used by the system. You can call the {@Link
25161847f8eSopenharmony_ci   * <br> GetAllSystemHotkeys} interface to query all system hotkeys.
25261847f8eSopenharmony_ci   * @throws { BusinessError } 4200003 - The hotkey has been subscribed to by another.
25361847f8eSopenharmony_ci   * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
25461847f8eSopenharmony_ci   * @since 13
25561847f8eSopenharmony_ci   */
25661847f8eSopenharmony_ci  function on(type: 'hotkeyChange', hotkeyOptions: HotkeyOptions, callback: Callback<HotkeyOptions>): void
25761847f8eSopenharmony_ci
25861847f8eSopenharmony_ci  /**
25961847f8eSopenharmony_ci   * Unsubscribe from hotkey event changes.
26061847f8eSopenharmony_ci   *
26161847f8eSopenharmony_ci   * @param { 'hotkeyChange' } type - Type of the hotkey events.
26261847f8eSopenharmony_ci   * @param { HotkeyOptions } hotkeyOptions - Hotkey events.
26361847f8eSopenharmony_ci   * @param { Callback<HotkeyOptions> } callback - Callback used to return hotkey events.
26461847f8eSopenharmony_ci   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;
26561847f8eSopenharmony_ci   * <br>2. Incorrect parameter types; 3. Parameter verification failed.
26661847f8eSopenharmony_ci   * @syscap SystemCapability.MultimodalInput.Input.InputConsumer
26761847f8eSopenharmony_ci   * @since 13
26861847f8eSopenharmony_ci   */
26961847f8eSopenharmony_ci  function off(type: 'hotkeyChange', hotkeyOptions: HotkeyOptions, callback?: Callback<HotkeyOptions>): void
27061847f8eSopenharmony_ci}
27161847f8eSopenharmony_ci
27261847f8eSopenharmony_ciexport default inputConsumer;