1/* 2 * Copyright (C) 2021-2025 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 { MouseEvent } from './@ohos.multimodalInput.mouseEvent'; 22import { TouchEvent } from './@ohos.multimodalInput.touchEvent'; 23/** 24 * The inputEventClient module implements the input event injection capability. 25 * 26 * @namespace inputEventClient 27 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 28 * @systemapi hide for inner use 29 * @since 8 30 */ 31declare namespace inputEventClient { 32 /** 33 * Defines the key event to inject. 34 * 35 * @interface KeyEvent 36 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 37 * @systemapi hide for inner use 38 * @since 8 39 */ 40 interface KeyEvent { 41 /** 42 * Whether the key is pressed. 43 * The value true indicates that the key is pressed, and the value false indicates the opposite. 44 * @type { boolean } 45 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 46 * @systemapi hide for inner use 47 * @since 8 48 */ 49 isPressed: boolean; 50 51 /** 52 * Keycode value. Currently, only the KEYCODE_BACK key is supported. 53 * @type { number } 54 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 55 * @systemapi hide for inner use 56 * @since 8 57 */ 58 keyCode: number; 59 60 /** 61 * Duration for pressing a key, in μs. 62 * @type { number } 63 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 64 * @systemapi hide for inner use 65 * @since 8 66 */ 67 keyDownDuration: number; 68 69 /** 70 * Whether the key event can be intercepted. 71 * The value true indicates that the key event can be intercepted, and the value false indicates the opposite. 72 * @type { boolean } 73 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 74 * @systemapi hide for inner use 75 * @since 8 76 */ 77 isIntercepted: boolean; 78 } 79 80 /** 81 * Defines the mouse event data. 82 * 83 * @interface MouseEventData 84 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 85 * @systemapi hide for inner use 86 * @since 11 87 */ 88 interface MouseEventData { 89 /** 90 * Mouse event data. 91 * 92 * @type { MouseEvent } 93 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 94 * @systemapi hide for inner use 95 * @since 11 96 */ 97 mouseEvent: MouseEvent; 98 99 /** 100 * Whether to use global coordinate to calculate injected mouse event. 101 * 102 * @type { ?boolean } 103 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 104 * @systemapi hide for inner use 105 * @since 20 106 * @arkts 1.1&1.2 107 */ 108 useGlobalCoordinate? : boolean; 109 } 110 111 /** 112 * Defines the touchscreen event data. 113 * 114 * @interface TouchEventData 115 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 116 * @systemapi hide for inner use 117 * @since 11 118 */ 119 interface TouchEventData { 120 /** 121 * Touchscreen event data. 122 * 123 * @type { TouchEvent } 124 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 125 * @systemapi hide for inner use 126 * @since 11 127 */ 128 touchEvent: TouchEvent; 129 130 /** 131 * Whether to use global coordinate to calculate injected touch event. 132 * 133 * @type { ?boolean } 134 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 135 * @systemapi hide for inner use 136 * @since 20 137 * @arkts 1.1&1.2 138 */ 139 useGlobalCoordinate?: boolean; 140 } 141 142 /** 143 * Defines the key event to inject. 144 * 145 * @interface KeyEventData 146 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 147 * @systemapi hide for inner use 148 * @since 11 149 */ 150 interface KeyEventData { 151 /** 152 * Key event to inject. 153 * 154 * @type { KeyEvent } 155 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 156 * @systemapi hide for inner use 157 * @since 11 158 */ 159 keyEvent: KeyEvent; 160 } 161 162 /** 163 * Injects key events (for both single keys and combination keys). 164 * 165 * @param { KeyEventData } keyEvent - Key event to inject. 166 * @throws { BusinessError } 202 - SystemAPI permission error. 167 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 168 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 169 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 170 * @systemapi hide for inner use 171 * @since 11 172 */ 173 /** 174 * Injects key events (for both single keys and combination keys). 175 * 176 * @permission ohos.permission.INJECT_INPUT_EVENT 177 * @param { KeyEventData } keyEvent - Key event to inject. 178 * @throws { BusinessError } 201 - Permission denied. 179 * @throws { BusinessError } 202 - SystemAPI permission error. 180 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 181 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 182 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 183 * @systemapi hide for inner use 184 * @since 12 185 */ 186 function injectKeyEvent(keyEvent: KeyEventData): void; 187 188 /** 189 * Injects keys (including single keys and combination keys). 190 * 191 * @param { { KeyEvent } } KeyEvent - Key event to inject. 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.InputSimulator 195 * @systemapi hide for inner use 196 * @since 8 197 */ 198 /** 199 * Injects keys (including single keys and combination keys). 200 * 201 * @permission ohos.permission.INJECT_INPUT_EVENT 202 * @param { { KeyEvent } } KeyEvent - Key event to inject. 203 * @throws { BusinessError } 201 - Permission denied. 204 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 205 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 206 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 207 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 208 * @systemapi hide for inner use 209 * @since 12 210 */ 211 function injectEvent({ KeyEvent: KeyEvent }): void; 212 213 /** 214 * Injects a mouse/touchpad event. 215 * 216 * @param { MouseEventData } mouseEvent - Mouse/touchpad event to inject. 217 * @throws { BusinessError } 202 - SystemAPI permission error. 218 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 219 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 220 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 221 * @systemapi hide for inner use 222 * @since 11 223 */ 224 /** 225 * Injects a mouse/touchpad event. 226 * 227 * @permission ohos.permission.INJECT_INPUT_EVENT 228 * @param { MouseEventData } mouseEvent - Mouse/touchpad event to inject. 229 * @throws { BusinessError } 201 - Permission denied. 230 * @throws { BusinessError } 202 - SystemAPI permission error. 231 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 232 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 233 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 234 * @systemapi hide for inner use 235 * @since 12 236 */ 237 function injectMouseEvent(mouseEvent: MouseEventData): void; 238 239 /** 240 * Injects a touchscreen event. 241 * 242 * @param { TouchEventData } touchEvent - Touchscreen event to inject. 243 * @throws { BusinessError } 202 - SystemAPI permission error. 244 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 245 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 246 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 247 * @systemapi hide for inner use 248 * @since 11 249 */ 250 /** 251 * Injects a touchscreen event. 252 * 253 * @permission ohos.permission.INJECT_INPUT_EVENT 254 * @param { TouchEventData } touchEvent - Touchscreen event to inject. 255 * @throws { BusinessError } 201 - Permission denied. 256 * @throws { BusinessError } 202 - SystemAPI permission error. 257 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 258 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 259 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 260 * @systemapi hide for inner use 261 * @since 12 262 */ 263 function injectTouchEvent(touchEvent: TouchEventData): void; 264 265 /** 266 * Specifies whether to authorize event injection. 267 * 268 * @permission ohos.permission.INJECT_INPUT_EVENT 269 * @param { boolean } result - Authorization result. The value true indicates that event injection is allowed, and the value false indicates the opposite. 270 * @throws { BusinessError } 201 - Permission denied. 271 * @throws { BusinessError } 202 - SystemAPI permission error. 272 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 273 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 274 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 275 * @systemapi hide for inner use 276 * @since 12 277 */ 278 function permitInjection(result: boolean): void; 279} 280 281export default inputEventClient;