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 13 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 * Whether to report repeated key events. By default, the value is true if it is left unspecified. 82 * 83 * @type { ?boolean } 84 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 85 * @systemapi hide for inner use 86 * @since 13 87 */ 88 isRepeat?: boolean; 89 } 90 91 /** 92 * Defines the shortcut key structure. 93 * 94 * @typedef HotkeyOptions 95 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 96 * @since 13 97 */ 98 interface HotkeyOptions { 99 /** 100 * Defines modifier keys. One or two modifier keys are supported. 101 * 102 * @type { Array<number> } 103 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 104 * @since 13 105 */ 106 preKeys: Array<number>; 107 108 /** 109 * Defines modified keys. 110 * 111 * @type { number } 112 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 113 * @since 13 114 */ 115 finalKey: number; 116 117 /** 118 * Whether to report repeated key events. By default, the value is true if it is left unspecified. 119 * 120 * @type { ?boolean } 121 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 122 * @since 13 123 */ 124 isRepeat?: boolean; 125 } 126 127 /** 128 * Shield mode. 129 * 130 * @enum { number } 131 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 132 * @systemapi hide for inner use 133 * @since 11 134 */ 135 enum ShieldMode { 136 /** 137 * Factory mode shield all key events 138 * 139 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 140 * @systemapi hide for inner use 141 * @since 11 142 */ 143 FACTORY_MODE 144 } 145 146 /** 147 * Subscribe system keys. 148 * 149 * @param { 'key' } type - type of the inputevent about input which is to be subscribed. 150 * @param { KeyOptions } keyOptions - the key events about input which is to be subscribed. 151 * @param { Callback<KeyOptions> } callback - callback function, receive reported data. 152 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 153 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 154 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 155 * @systemapi hide for inner use 156 * @since 8 157 */ 158 /** 159 * Subscribe system keys. 160 * 161 * @param { 'key' } type - type of the inputevent about input which is to be subscribed. 162 * @param { KeyOptions } keyOptions - the key events about input which is to be subscribed. 163 * @param { Callback<KeyOptions> } callback - callback function, receive reported data. 164 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 165 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 166 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 167 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 168 * @systemapi hide for inner use 169 * @since 12 170 */ 171 function on(type: 'key', keyOptions: KeyOptions, callback: Callback<KeyOptions>): void; 172 173 /** 174 * Subscribe system keys. 175 * 176 * @param { 'key' } type - type of the inputevent about input which is to be subscribed. 177 * @param { KeyOptions } keyOptions - the key events about input which is to be subscribed. 178 * @param { Callback<KeyOptions> } callback - callback function, receive reported data. 179 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 180 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 181 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 182 * @systemapi hide for inner use 183 * @since 8 184 */ 185 /** 186 * Subscribe system keys. 187 * 188 * @param { 'key' } type - type of the inputevent about input which is to be subscribed. 189 * @param { KeyOptions } keyOptions - the key events about input which is to be subscribed. 190 * @param { Callback<KeyOptions> } callback - callback function, receive reported data. 191 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 192 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 193 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 194 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 195 * @systemapi hide for inner use 196 * @since 12 197 */ 198 function off(type: 'key', keyOptions: KeyOptions, callback?: Callback<KeyOptions>): void; 199 200 /** 201 * Sets whether shield key event interception, only support shield key event. 202 * 203 * @permission ohos.permission.INPUT_CONTROL_DISPATCHING 204 * @param { ShieldMode } shieldMode - According the shield mode select shield key event range. 205 * @param { boolean } isShield - Indicates whether control key event dispatch. The value <b>true</b> indicates 206 * all key events directly dispatch to window, if the value <b>false</b> indicates not shield shortcut key. 207 * @throws { BusinessError } 201 - Permission denied. 208 * @throws { BusinessError } 202 - SystemAPI permission error. 209 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 210 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 211 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 212 * @systemapi hide for inner use. 213 * @since 11 214 */ 215 function setShieldStatus(shieldMode: ShieldMode, isShield: boolean): void; 216 217 /** 218 * Gets shield event interception status corresponding to shield mode 219 * 220 * @permission ohos.permission.INPUT_CONTROL_DISPATCHING 221 * @param { ShieldMode } shieldMode - According the shield mode select shield key event range. 222 * @returns { boolean } Returns true if shield event interception, returns false otherwise. 223 * @throws { BusinessError } 201 - Permission denied. 224 * @throws { BusinessError } 202 - SystemAPI permission error. 225 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 226 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 227 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 228 * @systemapi hide for inner use. 229 * @since 11 230 */ 231 function getShieldStatus(shieldMode: ShieldMode): boolean; 232 233 /** 234 * Obtains all system hotkeys. This API uses a promise to return the result. 235 * 236 * @Returns { Promise<Array<HotkeyOptions>> } All system hotkeys. 237 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 238 * @since 13 239 */ 240 function getAllSystemHotkeys(): Promise<Array<HotkeyOptions>>; 241 242 /** 243 * Listening for hotkey event changes. 244 * 245 * @param { 'hotkeyChange' } type - Type of the hotkey events. 246 * @param { HotkeyOptions } hotkeyOptions - hotkey events. 247 * @param { Callback<HotkeyOptions> } callback - Callback used to return hotkey events. 248 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 249 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 250 * @throws { BusinessError } 4200002 - The hotkey has been used by the system. You can call the {@Link 251 * <br> GetAllSystemHotkeys} interface to query all system hotkeys. 252 * @throws { BusinessError } 4200003 - The hotkey has been subscribed to by another. 253 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 254 * @since 13 255 */ 256 function on(type: 'hotkeyChange', hotkeyOptions: HotkeyOptions, callback: Callback<HotkeyOptions>): void 257 258 /** 259 * Unsubscribe from hotkey event changes. 260 * 261 * @param { 'hotkeyChange' } type - Type of the hotkey events. 262 * @param { HotkeyOptions } hotkeyOptions - Hotkey events. 263 * @param { Callback<HotkeyOptions> } callback - Callback used to return hotkey events. 264 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 265 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 266 * @syscap SystemCapability.MultimodalInput.Input.InputConsumer 267 * @since 13 268 */ 269 function off(type: 'hotkeyChange', hotkeyOptions: HotkeyOptions, callback?: Callback<HotkeyOptions>): void 270} 271 272export default inputConsumer;