1/* 2 * Copyright (C) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit InputKit 19 */ 20 21import { Callback } from './@ohos.base'; 22 23/** 24 * The event of key input management module is configured to subscribe and unsubscribe system keys. 25 * 26 * @namespace inputConsumer 27 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 28 * @since 14 29 */ 30declare namespace inputConsumer { 31 /** 32 * Defines event of key that user want to subscribe or unsubscribe. 33 * 34 * @interface KeyOptions 35 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 36 * @systemapi hide for inner use 37 * @since 8 38 */ 39 interface KeyOptions { 40 /** 41 * The pre-keys that want to subscribe or unsubscribe. 42 * 43 * @type { Array<number> } 44 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 45 * @systemapi hide for inner use 46 * @since 8 47 */ 48 preKeys: Array<number>; 49 50 /** 51 * The post position key that want to subscribe or unsubscribe. 52 * 53 * @type { number } 54 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 55 * @systemapi hide for inner use 56 * @since 8 57 */ 58 finalKey: number; 59 60 /** 61 * The final key press down or up. 62 * 63 * @type { boolean } 64 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 65 * @systemapi hide for inner use 66 * @since 8 67 */ 68 isFinalKeyDown: boolean; 69 70 /** 71 * Duration of final key press. 72 * 73 * @type { number } 74 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 75 * @systemapi hide for inner use 76 * @since 8 77 */ 78 finalKeyDownDuration: number; 79 } 80 81 /** 82 * Defines the shortcut key structure. 83 * 84 * @typedef HotkeyOptions 85 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 86 * @since 14 87 */ 88 interface HotkeyOptions { 89 /** 90 * Defines modifier keys. One or two modifier keys are supported. 91 * 92 * @type { Array<number> } 93 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 94 * @since 14 95 */ 96 preKeys: Array<number>; 97 98 /** 99 * Defines modified keys. 100 * 101 * @type { number } 102 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 103 * @since 14 104 */ 105 finalKey: number; 106 107 /** 108 * Whether to report repeated key events. By default, the value is true if it is left unspecified. 109 * 110 * @type { ?boolean } 111 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 112 * @since 14 113 */ 114 isRepeat?: boolean; 115 } 116 117 /** 118 * Shield mode. 119 * 120 * @enum { number } 121 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 122 * @systemapi hide for inner use 123 * @since 11 124 */ 125 enum ShieldMode { 126 /** 127 * Factory mode shield all key events 128 * 129 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 130 * @systemapi hide for inner use 131 * @since 11 132 */ 133 FACTORY_MODE 134 } 135 136 /** 137 * Subscribe system keys. 138 * 139 * @param { 'key' } type - type of the inputevent about input which is to be subscribed. 140 * @param { KeyOptions } keyOptions - the key events about input which is to be subscribed. 141 * @param { Callback<KeyOptions> } callback - callback function, receive reported data. 142 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 143 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 144 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 145 * @systemapi hide for inner use 146 * @since 8 147 */ 148 /** 149 * Subscribe system keys. 150 * 151 * @param { 'key' } type - type of the inputevent about input which is to be subscribed. 152 * @param { KeyOptions } keyOptions - the key events about input which is to be subscribed. 153 * @param { Callback<KeyOptions> } callback - callback function, receive reported data. 154 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 155 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 156 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 157 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 158 * @systemapi hide for inner use 159 * @since 12 160 */ 161 function on(type: 'key', keyOptions: KeyOptions, callback: Callback<KeyOptions>): void; 162 163 /** 164 * Subscribe system keys. 165 * 166 * @param { 'key' } type - type of the inputevent about input which is to be subscribed. 167 * @param { KeyOptions } keyOptions - the key events about input which is to be subscribed. 168 * @param { Callback<KeyOptions> } callback - callback function, receive reported data. 169 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 170 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 171 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 172 * @systemapi hide for inner use 173 * @since 8 174 */ 175 /** 176 * Subscribe system keys. 177 * 178 * @param { 'key' } type - type of the inputevent about input which is to be subscribed. 179 * @param { KeyOptions } keyOptions - the key events about input which is to be subscribed. 180 * @param { Callback<KeyOptions> } callback - callback function, receive reported data. 181 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 182 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 183 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 184 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 185 * @systemapi hide for inner use 186 * @since 12 187 */ 188 function off(type: 'key', keyOptions: KeyOptions, callback?: Callback<KeyOptions>): void; 189 190 /** 191 * Sets whether shield key event interception, only support shield key event. 192 * 193 * @permission ohos.permission.INPUT_CONTROL_DISPATCHING 194 * @param { ShieldMode } shieldMode - According the shield mode select shield key event range. 195 * @param { boolean } isShield - Indicates whether control key event dispatch. The value <b>true</b> indicates 196 * all key events directly dispatch to window, if the value <b>false</b> indicates not shield shortcut key. 197 * @throws { BusinessError } 201 - Permission denied. 198 * @throws { BusinessError } 202 - SystemAPI permission error. 199 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 200 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 201 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 202 * @systemapi hide for inner use. 203 * @since 11 204 */ 205 function setShieldStatus(shieldMode: ShieldMode, isShield: boolean): void; 206 207 /** 208 * Gets shield event interception status corresponding to shield mode 209 * 210 * @permission ohos.permission.INPUT_CONTROL_DISPATCHING 211 * @param { ShieldMode } shieldMode - According the shield mode select shield key event range. 212 * @returns { boolean } Returns true if shield event interception, returns false otherwise. 213 * @throws { BusinessError } 201 - Permission denied. 214 * @throws { BusinessError } 202 - SystemAPI permission error. 215 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 216 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 217 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 218 * @systemapi hide for inner use. 219 * @since 11 220 */ 221 function getShieldStatus(shieldMode: ShieldMode): boolean; 222 223 /** 224 * Obtains all system hotkeys. This API uses a promise to return the result. 225 * 226 * @returns { Promise<Array<HotkeyOptions>> } All system hotkeys. 227 * @throws { BusinessError } 801 - Capability not supported. 228 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 229 * @since 14 230 */ 231 function getAllSystemHotkeys(): Promise<Array<HotkeyOptions>>; 232 233 /** 234 * Listening for hotkey event changes. 235 * 236 * @param { 'hotkeyChange' } type - Type of the hotkey events. 237 * @param { HotkeyOptions } hotkeyOptions - hotkey events. 238 * @param { Callback<HotkeyOptions> } callback - Callback used to return hotkey events. 239 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 240 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 241 * @throws { BusinessError } 801 - Capability not supported. 242 * @throws { BusinessError } 4200002 - The hotkey has been used by the system. 243 * @throws { BusinessError } 4200003 - The hotkey has been subscribed to by another. 244 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 245 * @since 14 246 */ 247 function on(type: 'hotkeyChange', hotkeyOptions: HotkeyOptions, callback: Callback<HotkeyOptions>): void; 248 249 /** 250 * Unsubscribe from hotkey event changes. 251 * 252 * @param { 'hotkeyChange' } type - Type of the hotkey events. 253 * @param { HotkeyOptions } hotkeyOptions - Hotkey events. 254 * @param { Callback<HotkeyOptions> } callback - Callback used to return hotkey events. 255 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 256 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 257 * @throws { BusinessError } 801 - Capability not supported. 258 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 259 * @since 14 260 */ 261 function off(type: 'hotkeyChange', hotkeyOptions: HotkeyOptions, callback?: Callback<HotkeyOptions>): void; 262} 263 264export default inputConsumer;