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'; 22import { MouseEvent } from './@ohos.multimodalInput.mouseEvent'; 23import type display from './@ohos.display'; 24import type { TouchEvent } from './@ohos.multimodalInput.touchEvent'; 25import type { Rotate, Pinch, ThreeFingersSwipe, FourFingersSwipe } from './@ohos.multimodalInput.gestureEvent'; 26import type { ThreeFingersTap } from './@ohos.multimodalInput.gestureEvent'; 27 28/** 29 * Global input event listener 30 * System API, available only to system processes 31 * 32 * @namespace inputMonitor 33 * @permission ohos.permission.INPUT_MONITORING 34 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 35 * @systemapi hide for inner use 36 * @since 7 37 */ 38declare namespace inputMonitor { 39 /** 40 * Callback used to receive touch input events. If **true** is returned, the touch input is consumed, 41 * and the system performs the closing operation. 42 * 43 * @interface TouchEventReceiver 44 * @permission ohos.permission.INPUT_MONITORING 45 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 46 * @systemapi hide for inner use 47 * @since 7 48 */ 49 interface TouchEventReceiver { 50 /** 51 * Callback used to receive touch input events. 52 * 53 * @param { TouchEvent } touchEvent - the reported touch event. 54 * @returns { Boolean } Returns true indicates the touch input is consumed, the value false indicates opposite. 55 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 56 * @systemapi hide for inner use 57 * @since 7 58 */ 59 (touchEvent: TouchEvent): Boolean; 60 } 61 62 /** 63 * Listens for touch input events. 64 * 65 * @permission ohos.permission.INPUT_MONITORING 66 * @param { 'touch' } type - Event type, which is **touch**. 67 * @param { TouchEventReceiver } receiver - Callback used to receive the reported data. 68 * @throws { BusinessError } 401 - Parameter error. 69 * @throws { BusinessError } 201 - Permission denied. 70 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 71 * @systemapi hide for inner use 72 * @since 7 73 */ 74 function on(type: 'touch', receiver: TouchEventReceiver): void; 75 76 /** 77 * Listens for mouse input events. 78 * 79 * @permission ohos.permission.INPUT_MONITORING 80 * @param { 'mouse' } type - Event type, which is **mouse**. 81 * @param { Callback<MouseEvent> } receiver - Callback used to receive the reported data. 82 * @throws { BusinessError } 401 - Parameter error. 83 * @throws { BusinessError } 201 - Permission denied. 84 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 85 * @systemapi hide for inner use 86 * @since 9 87 */ 88 function on(type: 'mouse', receiver: Callback<MouseEvent>): void; 89 90 /** 91 * Listens for mouse input events when the mouse arrow is within the specified rectangular area. 92 * 93 * @permission ohos.permission.INPUT_MONITORING 94 * @param { 'mouse' } type - Event type, which is **mouse**. 95 * @param { display.Rect[] } rect - A specified rectangular area that can trigger a callback, with a maximum of two. 96 * @param { Callback<MouseEvent> } receiver - Callback used to receive the reported data. 97 * @throws { BusinessError } 401 - Parameter error. 98 * @throws { BusinessError } 201 - Permission denied. 99 * @throws { BusinessError } 202 - SystemAPI permit error. 100 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 101 * @systemapi hide for inner use 102 * @since 11 103 */ 104 function on(type: 'mouse', rect: display.Rect[], receiver: Callback<MouseEvent>): void; 105 106 /** 107 * Cancel listening for touch input events. 108 * 109 * @permission ohos.permission.INPUT_MONITORING 110 * @param { 'touch' } type - Event type, which is **touch**. 111 * @param { TouchEventReceiver } receiver - Callback used to receive the reported data. 112 * @throws { BusinessError } 401 - Parameter error. 113 * @throws { BusinessError } 201 - Permission denied. 114 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 115 * @systemapi hide for inner use 116 * @since 7 117 */ 118 function off(type: 'touch', receiver?: TouchEventReceiver): void; 119 120 /** 121 * Cancel listening for mouse input events. 122 * 123 * @permission ohos.permission.INPUT_MONITORING 124 * @param { 'mouse' } type - Event type, which is **mouse**. 125 * @param { Callback<MouseEvent> } receiver - Callback used to receive the reported data. 126 * @throws { BusinessError } 401 - Parameter error. 127 * @throws { BusinessError } 201 - Permission denied. 128 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 129 * @systemapi hide for inner use 130 * @since 9 131 */ 132 function off(type: 'mouse', receiver?: Callback<MouseEvent>): void; 133 134 /** 135 * Listens for touchPad pinch events. 136 * 137 * @permission ohos.permission.INPUT_MONITORING 138 * @param { 'pinch' } type - Event type, which is **pinch**. 139 * @param { Callback<Pinch> } receiver - Callback used to receive the reported data. 140 * @throws { BusinessError } 201 - Permission denied. 141 * @throws { BusinessError } 202 - SystemAPI permit error. 142 * @throws { BusinessError } 401 - Parameter error. 143 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 144 * @systemapi hide for inner use 145 * @since 10 146 */ 147 function on(type: 'pinch', receiver: Callback<Pinch>): void; 148 149 /** 150 * Cancel listening for touchPad pinch events. 151 * 152 * @permission ohos.permission.INPUT_MONITORING 153 * @param { 'pinch' } type - Event type, which is **pinch**. 154 * @param { Callback<Pinch> } receiver - Callback used to receive the reported data. 155 * @throws { BusinessError } 201 - Permission denied. 156 * @throws { BusinessError } 202 - SystemAPI permit error. 157 * @throws { BusinessError } 401 - Parameter error. 158 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 159 * @systemapi hide for inner use 160 * @since 10 161 */ 162 function off(type: 'pinch', receiver?: Callback<Pinch>): void; 163 164 /** 165 * Listens for touchPad fingers pinch events. 166 * 167 * @permission ohos.permission.INPUT_MONITORING 168 * @param { 'pinch' } type - Event type, which is **pinch**. 169 * @param { number } fingers - the number of fingers. 170 * @param { Callback<Pinch> } receiver - Callback used to receive the reported data. 171 * @throws { BusinessError } 201 - Permission denied. 172 * @throws { BusinessError } 202 - SystemAPI permit error. 173 * @throws { BusinessError } 401 - Parameter error. 174 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 175 * @systemapi hide for inner use 176 * @since 11 177 */ 178 function on(type: 'pinch', fingers: number, receiver: Callback<Pinch>): void; 179 180 /** 181 * Cancel listening for touchPad fingers pinch events. 182 * 183 * @permission ohos.permission.INPUT_MONITORING 184 * @param { 'pinch' } type - Event type, which is **pinch**. 185 * @param { number } fingers - the number of fingers. 186 * @param { Callback<Pinch> } receiver - Callback used to receive the reported data. 187 * @throws { BusinessError } 201 - Permission denied. 188 * @throws { BusinessError } 202 - SystemAPI permit error. 189 * @throws { BusinessError } 401 - Parameter error. 190 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 191 * @systemapi hide for inner use 192 * @since 11 193 */ 194 function off(type: 'pinch', fingers: number, receiver?: Callback<Pinch>): void; 195 196 /** 197 * Listens for touchPad fingers rotate events. 198 * 199 * @permission ohos.permission.INPUT_MONITORING 200 * @param { 'rotate' } type - Event type, which is **rotate**. 201 * @param { number } fingers - the number of fingers. 202 * @param { Callback<Rotate> } receiver - Callback used to receive the reported data. 203 * @throws { BusinessError } 201 - Permission denied. 204 * @throws { BusinessError } 202 - SystemAPI permit error. 205 * @throws { BusinessError } 401 - Parameter error. 206 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 207 * @systemapi hide for inner use 208 * @since 11 209 */ 210 function on(type: 'rotate', fingers: number, receiver: Callback<Rotate>): void; 211 212 /** 213 * Cancel listening for touchPad fingers rotate events. 214 * 215 * @permission ohos.permission.INPUT_MONITORING 216 * @param { 'rotate' } type - Event type, which is **rotate**. 217 * @param { number } fingers - the number of fingers. 218 * @param { Callback<Rotate> } receiver - Callback used to receive the reported data. 219 * @throws { BusinessError } 201 - Permission denied. 220 * @throws { BusinessError } 202 - SystemAPI permit error. 221 * @throws { BusinessError } 401 - Parameter error. 222 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 223 * @systemapi hide for inner use 224 * @since 11 225 */ 226 function off(type: 'rotate', fingers: number, receiver?: Callback<Rotate>): void; 227 228 /** 229 * Listens for touchPad three fingers swipe events. 230 * 231 * @permission ohos.permission.INPUT_MONITORING 232 * @param { 'threeFingersSwipe' } type - Event type, which is **threeFingersSwipe**. 233 * @param { Callback<ThreeFingersSwipe> } receiver - Callback used to receive the reported data. 234 * @throws { BusinessError } 201 - Permission denied. 235 * @throws { BusinessError } 202 - SystemAPI permit error. 236 * @throws { BusinessError } 401 - Parameter error. 237 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 238 * @systemapi hide for inner use 239 * @since 10 240 */ 241 function on(type: 'threeFingersSwipe', receiver: Callback<ThreeFingersSwipe>): void; 242 243 /** 244 * Cancel listening touchPad three fingers swipe events. 245 * 246 * @permission ohos.permission.INPUT_MONITORING 247 * @param { 'threeFingersSwipe' } type - Event type, which is **threeFingersSwipe**. 248 * @param { Callback<ThreeFingersSwipe> } receiver - Callback used to receive the reported data. 249 * @throws { BusinessError } 201 - Permission denied. 250 * @throws { BusinessError } 202 - SystemAPI permit error. 251 * @throws { BusinessError } 401 - Parameter error. 252 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 253 * @systemapi hide for inner use 254 * @since 10 255 */ 256 function off(type: 'threeFingersSwipe', receiver?: Callback<ThreeFingersSwipe>): void; 257 258 /** 259 * Listens for touchPad four fingers swipe events. 260 * 261 * @permission ohos.permission.INPUT_MONITORING 262 * @param { 'fourFingersSwipe' } type - Event type, which is **fourFingersSwipe**.. 263 * @param { Callback<FourFingersSwipe> } receiver - Callback used to receive the reported data. 264 * @throws { BusinessError } 201 - Permission denied. 265 * @throws { BusinessError } 202 - SystemAPI permit error. 266 * @throws { BusinessError } 401 - Parameter error. 267 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 268 * @systemapi hide for inner use 269 * @since 10 270 */ 271 function on(type: 'fourFingersSwipe', receiver: Callback<FourFingersSwipe>): void; 272 273 /** 274 * Cancel listening touchPad four finger swipe events. 275 * 276 * @permission ohos.permission.INPUT_MONITORING 277 * @param { 'fourFingersSwipe' } type - Event type, which is **fourFingersSwipe**. 278 * @param { Callback<FourFingersSwipe> } receiver - Callback used to receive the reported data. 279 * @throws { BusinessError } 201 - Permission denied. 280 * @throws { BusinessError } 202 - SystemAPI permit error. 281 * @throws { BusinessError } 401 - Parameter error. 282 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 283 * @systemapi hide for inner use 284 * @since 10 285 */ 286 function off(type: 'fourFingersSwipe', receiver?: Callback<FourFingersSwipe>): void; 287 288 /** 289 * Listens for touchPad three fingers tap events. 290 * 291 * @permission ohos.permission.INPUT_MONITORING 292 * @param { 'threeFingersTap' } type - Event type, which is **threeFingersTap**. 293 * @param { Callback<ThreeFingersTap> } receiver - Callback used to receive the reported data. 294 * @throws { BusinessError } 201 - Permission denied. 295 * @throws { BusinessError } 202 - SystemAPI permit error. 296 * @throws { BusinessError } 401 - Parameter error. 297 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 298 * @systemapi hide for inner use 299 * @since 11 300 */ 301 function on(type: 'threeFingersTap', receiver: Callback<ThreeFingersTap>): void; 302 303 /** 304 * Cancel listening touchPad three fingers tap events. 305 * 306 * @permission ohos.permission.INPUT_MONITORING 307 * @param { 'threeFingersTap' } type - Event type, which is **threeFingersTap**. 308 * @param { Callback<ThreeFingersTap> } receiver - Callback used to receive the reported data. 309 * @throws { BusinessError } 201 - Permission denied. 310 * @throws { BusinessError } 202 - SystemAPI permit error. 311 * @throws { BusinessError } 401 - Parameter error. 312 * @syscap SystemCapability.MultimodalInput.Input.InputMonitor 313 * @systemapi hide for inner use 314 * @since 11 315 */ 316 function off(type: 'threeFingersTap', receiver?: Callback<ThreeFingersTap>): void; 317 318} 319export default inputMonitor; 320