1/* 2 * Copyright (C) 2021 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 * Global Key Event Injection 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 event of key that user want 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 * The status of key. 43 * @type { boolean } 44 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 45 * @systemapi hide for inner use 46 * @since 8 47 */ 48 isPressed: boolean; 49 50 /** 51 * The keyCode value of key. 52 * @type { number } 53 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 54 * @systemapi hide for inner use 55 * @since 8 56 */ 57 keyCode: number; 58 59 /** 60 * Key hold duration. 61 * @type { number } 62 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 63 * @systemapi hide for inner use 64 * @since 8 65 */ 66 keyDownDuration: number; 67 68 /** 69 * Whether the key is blocked. 70 * @type { boolean } 71 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 72 * @systemapi hide for inner use 73 * @since 8 74 */ 75 isIntercepted: boolean; 76 } 77 78 /** 79 * Defines event of mouse that user want to inject. 80 * 81 * @interface MouseEventData 82 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 83 * @systemapi hide for inner use 84 * @since 11 85 */ 86 interface MouseEventData { 87 /** 88 * Inject mouse event. 89 * 90 * @type { MouseEvent } 91 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 92 * @systemapi hide for inner use 93 * @since 11 94 */ 95 mouseEvent: MouseEvent; 96 } 97 98 /** 99 * Defines event of touch that user want to inject. 100 * 101 * @interface TouchEventData 102 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 103 * @systemapi hide for inner use 104 * @since 11 105 */ 106 interface TouchEventData { 107 /** 108 * Inject touch event. 109 * 110 * @type { TouchEvent } 111 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 112 * @systemapi hide for inner use 113 * @since 11 114 */ 115 touchEvent: TouchEvent; 116 } 117 118 /** 119 * Defines event of key that user want to inject. 120 * 121 * @interface KeyEventData 122 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 123 * @systemapi hide for inner use 124 * @since 11 125 */ 126 interface KeyEventData { 127 /** 128 * Inject key event. 129 * 130 * @type { KeyEvent } 131 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 132 * @systemapi hide for inner use 133 * @since 11 134 */ 135 keyEvent: KeyEvent; 136 } 137 138 /** 139 * Inject system keys. 140 * 141 * @param { KeyEventData } keyEvent - the key event to be injected. 142 * @throws { BusinessError } 202 - SystemAPI permission error. 143 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 144 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 145 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 146 * @systemapi hide for inner use 147 * @since 11 148 */ 149 /** 150 * Inject system keys. 151 * 152 * @permission ohos.permission.INJECT_INPUT_EVENT 153 * @param { KeyEventData } keyEvent - the key event to be injected. 154 * @throws { BusinessError } 201 - Permission denied. 155 * @throws { BusinessError } 202 - SystemAPI permission error. 156 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 157 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 158 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 159 * @systemapi hide for inner use 160 * @since 12 161 */ 162 function injectKeyEvent(keyEvent: KeyEventData): void; 163 164 /** 165 * Inject system keys. 166 * 167 * @param { { KeyEvent } } KeyEvent - the key event to be injected. 168 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 169 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 170 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 171 * @systemapi hide for inner use 172 * @since 8 173 */ 174 /** 175 * Inject system keys. 176 * 177 * @permission ohos.permission.INJECT_INPUT_EVENT 178 * @param { { KeyEvent } } KeyEvent - the key event to be injected. 179 * @throws { BusinessError } 201 - Permission denied. 180 * @throws { BusinessError } 202 - Permission denied, non-system app called system api. 181 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 182 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 183 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 184 * @systemapi hide for inner use 185 * @since 12 186 */ 187 function injectEvent({ KeyEvent: KeyEvent }): void; 188 189 /** 190 * Inject mouse event. 191 * 192 * @param { MouseEventData } mouseEvent - the mouse event to be injected. 193 * @throws { BusinessError } 202 - SystemAPI permission error. 194 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 195 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 196 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 197 * @systemapi hide for inner use 198 * @since 11 199 */ 200 /** 201 * Inject mouse event. 202 * 203 * @permission ohos.permission.INJECT_INPUT_EVENT 204 * @param { MouseEventData } mouseEvent - the mouse event to be injected. 205 * @throws { BusinessError } 201 - Permission denied. 206 * @throws { BusinessError } 202 - SystemAPI permission error. 207 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 208 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 209 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 210 * @systemapi hide for inner use 211 * @since 12 212 */ 213 function injectMouseEvent(mouseEvent: MouseEventData): void; 214 215 /** 216 * Inject touch event. 217 * 218 * @param { TouchEventData } touchEvent - the touch event to be injected. 219 * @throws { BusinessError } 202 - SystemAPI permission error. 220 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 221 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 222 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 223 * @systemapi hide for inner use 224 * @since 11 225 */ 226 /** 227 * Inject touch event. 228 * 229 * @permission ohos.permission.INJECT_INPUT_EVENT 230 * @param { TouchEventData } touchEvent - the touch event to be injected. 231 * @throws { BusinessError } 201 - Permission denied. 232 * @throws { BusinessError } 202 - SystemAPI permission error. 233 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 234 * <br>2. Incorrect parameter types; 3. Parameter verification failed. 235 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 236 * @systemapi hide for inner use 237 * @since 12 238 */ 239 function injectTouchEvent(touchEvent: TouchEventData): void; 240 241 /** 242 * Permit event injection permission. 243 * 244 * @permission ohos.permission.INJECT_INPUT_EVENT 245 * @param { boolean } result - Authorization result. 246 * @throws { BusinessError } 201 - Permission denied. 247 * @throws { BusinessError } 202 - SystemAPI permission error. 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 * @syscap SystemCapability.MultimodalInput.Input.InputSimulator 251 * @systemapi hide for inner use 252 * @since 12 253 */ 254 function permitInjection(result: boolean): void; 255} 256 257export default inputEventClient; 258