1# uinput 2 3uinput can simulate users to operate devices such as the mouse, keyboard, and touchpad for pressure tests like stability tests. 4 5## Environment Setup 6 7- The [environment setup](hdc.md#environment-setup) is complete. 8 9- The devices are properly connected. 10 11## Features 12 13**Usage** 14```bash 15uinput <option> <command> <arg> ... 16``` 17 18**Available Commands** 19| Abbreviation | Full Command | Description | 20| -------- | -------- | -------- | 21| -M | --mouse | Injects a mouse event. | 22| -K | --keyboard | Injects a keyboard event. | 23| -S | --stylus | Injects a stylus event.| 24| -T | --touch | Injects a touch event. | 25| -P | --touchpad | Injects a touchpad event.| 26| -? | --help | Displays the help information. | 27 28> **NOTE** 29> 30> The unit of the coordinate-related parameters in the command is [px (pixel units)](../reference/apis-arkui/arkui-ts/ts-pixel-units.md). 31 32## Help Command 33 34Displays the commands supported by the uinput tool. 35 36**Command** 37```bash 38uinput -? 39uinput --help 40``` 41 42**Example** 43```bash 44# Display the help information. 45uinput -? 46 47# Execution result. 48sage: uinput <option> <command> <arg>... 49The options are: 50-K --keyboard 51commands for keyboard: 52-d <key> --down <key> -press down a key 53-u <key> --up <key> -release a key 54-l <key> [long press time] --long_press <key> [long press time] -press and hold the key 55-r <key> [repeat output time] --repeat output <key> [repeat output time] -press and hold the key 56-i <time> --interval <time> -the program interval for the (time) milliseconds 57 58... 59 60``` 61 62## Mouse Events 63 64Simulates mouse move and click events. 65 66### Mouse Move Event 67Moves a mouse pointer to a relative position (dx, dy). 68 69**Command** 70```bash 71uinput -M -m <dx> <dy> 72uinput --mouse --move <dx> <dy> 73``` 74 75**Example** 76```bash 77# Move a mouse pointer to the relative position (100, 100). 78uinput -M -m 100 100 79``` 80 81**Extended Commands** 82```bash 83uinput -M -m <dx1> <dy1> <dx2> <dy2> [smooth time] --trace 84uinput --mouse --move <dx1> <dy1> <dx2> <dy2> [smooth time] --trace 85 86The trace option can be added to simulate the relative position and process of a mouse move event. 87[smooth time] specifies the moving time, whose default value is 1000 ms. The value can be set between 1 and 15000 ms. 88``` 89 90**Example** 91```bash 92# Move a mouse pointer from (100, 100) to (200, 200) for 1500 ms. 93uinput -M -m 100 100 200 200 1500 --trace 94``` 95 96### Mouse Down Event 97Presses a mouse button. This command is used with the mouse up command. For details about key values, see [Mouse Buttons](#mouse-buttons) 98 99**Command** 100```bash 101uinput -M -d <key> 102uinput --mouse --down <key> 103``` 104 105### Mouse Up Event 106Releases a mouse button. This command is used with the mouse down command. For details about key values, see [Mouse Buttons](#mouse-buttons) 107 108**Command** 109```bash 110uinput -M -u <key> 111uinput --mouse --up <key> 112``` 113 114**Example** 115```bash 116# Press down the left mouse button and release it. 117uinput -M -d 0 -u 0 118``` 119 120### Click Event 121Clicks a mouse button. For details about key values, see [Mouse Buttons](#mouse-buttons) 122 123**Command** 124```bash 125uinput -M -c <key> 126uinput --mouse --click <key> 127``` 128 129**Example** 130```bash 131# Click the left mouse button. 132uinput -M -c 0 133``` 134 135### Double-Click Event 136Double-clicks a mouse button. For details about key values, see [Mouse Buttons](#mouse-buttons) 137 138**Command** 139```bash 140uinput -M -b <dx> <dy> <id> [press time] [click interval time] 141uinput --mouse --double_click <dx> <dy> <id> [press time] [click interval time] 142 143The value of [press time] can be set between 1 and 300 ms. 144The value of [click interval time] can be set between 1 and 450 ms. 145The interval time must be within the value range. Otherwise, an error or invalid operation may occur. 146``` 147 148**Example** 149```bash 150# Double-click the coordinates (100, 150). 151uinput -M -b 100 150 0 10 10 152``` 153 154### Mouse Scroll Event 155Scrolls a mouse wheel backwards. 156 157**Command** 158```bash 159uinput -M -s <number> 160uinput --mouse --scroll <number> 161 162number indicates the amount of the mouse scrolling notches. One notch is 15. 163``` 164 165**Example** 166```bash 167# Scroll the mouse wheel backwards for three notches. 168uinput -M -s 45 169``` 170 171### Mouse Drag Event 172Drags a mouse. 173 174**Command** 175```bash 176uinput -M -g <dx1> <dy1> <dx2> <dy2> [total time] 177uinput --mouse --drag <dx1> <dy1> <dx2> <dy2> [total time] 178 179The [total time] parameter is optional, whose default value is 3000 ms. The value can be set between 3000 and 15000 ms. 180``` 181 182**Example** 183```bash 184# Click and drag a mouse from coordinates (100, 150) to (500, 300) at a specified time, and then release the mouse. 185uinput -M -g 100 150 500 300 186``` 187 188### Mouse Event Interval 189Sets the interval of mouse events, in milliseconds. 190 191**Command** 192```bash 193uinput -M -i <time> 194uinput --mouse --interval <time> 195``` 196 197**Example** 198```bash 199# Set the interval between two click events to 500 ms. 200uinput -M -c 0 -i 500 -c 0 201``` 202 203### Mouse Buttons 204| key | Description| 205| -------- | -------- | 206| 0 | Left mouse button. | 207| 1 | Right mouse button. | 208| 2 | Middle mouse button. | 209| 3 | Side mouse button.| 210| 4 | Extended mouse button.| 211| 5 | Mouse forward button.| 212| 6 | Mouse back button.| 213| 7 | Mouse task button.| 214 215## Keyboard Events 216 217Simulates the keyboard input events in the edit box. 218 219### Key Down Event 220Presses a key. This command is used with the key up command. For details about the keycode values, see [KeyCode](../reference/apis-input-kit/js-apis-keycode.md). 221 222**Command** 223```bash 224uinput -K -d <key> 225uinput --keyboard --down <key> 226``` 227 228### Key Up Event 229Releases a key. This command is used with the key down command. For details about the keycode values, see [KeyCode](../reference/apis-input-kit/js-apis-keycode.md). 230 231**Command** 232```bash 233uinput -K -u <key> 234uinput --keyboard --up <key> 235``` 236 237**Example** 238```bash 239# Press the A key and release it. 240uinput -K -d 2017 -u 2017 241``` 242 243### Long-Press Key Event 244Presses a key for a specified duration. For details about the keycode values, see [KeyCode](../reference/apis-input-kit/js-apis-keycode.md). 245 246**Command** 247```bash 248uinput -K -l <key> [long press time] 249uinput --keyboard --long_press <key> [long press time] 250``` 251 252**Example** 253```bash 254# Press and hold the A key for 100 ms, and then release the key. 255uinput -K -l 2017 100 256``` 257 258### Repeat Key Event 259Press a key and repeat the pressing for a specified time. For details about the keycode values, see [KeyCode](../reference/apis-input-kit/js-apis-keycode.md). 260 261**Command** 262```bash 263uinput -K -r <key> [repeat output time] 264uinput --keyboard --repeat <key> [repeat output time] 265``` 266 267**Example** 268```bash 269# Press the A key and repeat the pressing within 100 ms. 270uinput -K -r 2017 100 271``` 272 273### Keyboard Event Interval 274Sets the interval of keyboard events, in milliseconds. 275 276**Command** 277```bash 278uinput -K -i <time> 279uinput --keyboard --interval <time> 280``` 281 282**Example** 283```bash 284# Set the interval between pressing and releasing the A key to 500 ms. 285uinput -K -d 2017 -i 500 -u 2017 286``` 287 288### Keyboard Text Event 289Enters text using the keyboard. This command cannot be used together with other commands. Only a maximum of 2000 ASCLL characters are supported. 290 291**Command** 292```bash 293uinput -K -t <text> 294uinput --keyboard --text <text> 295``` 296 297**Example** 298```bash 299# Input 123 in the text box. 300uinput -K -t 123 301``` 302 303## Stylus Events 304 305Simulates stylus click and move events. 306 307### Stylus Down Event 308Press a stylus at coordinates (dx, dy). This command is used together with the stylus up command. 309 310**Command** 311```bash 312uinput -S -d <dx> <dy> 313uinput --stylus --down <dx> <dy> 314``` 315 316### Stylus Up Event 317Lifts a stylus at coordinates (dx, dy). This command is used together with the stylus down command. 318 319**Command** 320```bash 321uinput -S -u <dx> <dy> 322uinput --stylus --up <dx> <dy> 323``` 324 325**Example** 326```bash 327# Press and lift a stylus at coordinates (100, 100). 328uinput -S -d 100 100 -u 100 100 329``` 330 331### Stylus Move Event 332Moves a stylus from coordinates (dx1, dy1) to coordinates (dx2, dy2) after smooth time (ms) and then lifts the stylus. 333 334**Command** 335```bash 336uinput -S -m <dx1> <dy1> <dx2> <dy2> [smooth time] [-k keep time] 337uinput --stylus --move <dx1> <dy1> <dx2> <dy2> [smooth time] [-k keep time] 338 339The [smooth time] parameter is optional, whose default value is 1000 ms. The value can be set between 1 and 15000 ms. 340The [-k keep time] parameter is optional, whose default value is 0 ms. The value can be set between 0 and 60000 ms. 341``` 342 343**Example** 344```bash 345# Move a stylus from coordinates (100, 100) to coordinates (200, 200) for 1000 ms and then lift the stylus. 346uinput -S -m 100 100 200 200 1000 -k 1000 347``` 348 349### Stylus Click Event 350Clicks a stylus at coordinates (dx, dy). 351 352**Command** 353```bash 354uinput -S -c <dx> <dy> [click interval] 355uinput --stylus --click <dx> <dy> [click interval] 356 357The value of [click interval] can be set between 1 and 450 ms. 358``` 359 360**Example** 361```bash 362# Click a stylus at coordinates (100, 100). 363uinput -S -c 100 100 364``` 365 366### Stylus Drag Event 367Drags a stylus. 368 369**Command** 370```bash 371uinput -S -g <dx1> <dy1> <dx2> <dy2> [press time] [total time] 372uinput --stylus --drag <dx1> <dy1> <dx2> <dy2> [press time] [total time] 373 374The value of [Press time] cannot be less than 500 ms. 375[total time] specifies the total time of the drag operation. The value of [total time] and [Press time] cannot be less than 500 ms. Otherwise, an error or invalid operation may occur. 376``` 377 378**Example** 379```bash 380# Drag a stylus from coordinates (100, 150) to coordinates (500, 300) for 1100 ms. 381uinput -S -g 100 150 500 300 500 1100 382``` 383 384### Interval of Stylus Events 385Sets the interval of stylus events, in milliseconds. 386 387**Command** 388```bash 389uinput -S -i <time> 390uinput --stylus --interval <time> 391``` 392 393**Example** 394```bash 395# Set the interval between the two click events at coordinates (100,100) to 500 ms. 396uinput -S -c 100 100 -i 500 -c 100 100 397``` 398 399## Touch Events 400 401Simulates touch events such as touch click and move events. 402 403### Touch Down Event 404Simulates a finger touch at coordinates (dx, dy). This command is used together with the touch up command. 405 406**Command** 407```bash 408uinput -T -d <dx> <dy> 409uinput --touch --down <dx> <dy> 410``` 411 412### Touch Up Event 413Lifts a finger off the coordinates (dx, dy). This command is used together with the touch down command. 414 415**Command** 416```bash 417uinput -T -u <dx> <dy> 418uinput --touch --up <dx> <dy> 419``` 420 421**Example** 422```bash 423# Touch coordinates (100, 100) and lift the finger off. 424uinput -T -d 100 100 -u 100 100 425``` 426 427### Touch Move Event 428Moves the finger from coordinates (dx1, dy1) to coordinates (dx2, dy2) after smooth time (ms). A maximum of three fingers can be moved at the same time. 429 430**Command** 431```bash 432uinput -T -m <dx1> <dy1> <dx2> <dy2> [-k keep time] [smooth time] 433uinput --touch --move <dx1> <dy1> <dx2> <dy2> [-k keep time] [smooth time] 434 435The [-k keep time] parameter is optional, whose default value is 0 ms. The value can be set between 0 and 60000 ms. 436The [smooth time] parameter is optional, whose default value is 1000 ms. The value can be set between 1 and 15000 ms. 437``` 438 439**Example** 440```bash 441# Move the finger from coordinates (100, 100) to coordinates (200, 200) for 1000 ms and then lift the finger. 442uinput -T -m 100 100 200 200 1000 -k 1000 443 444# Move three fingers for 200 ms, with the first finger moving from (300, 900) to (300,2000), the second finger moving from (600,900) to (600,2000), and the third finger moving from (900,900) to (900,2000). After the movement, hold the screen for 1000 ms and then lift the finger. 445uinput -T -m 300 900 300 2000 600 900 600 2000 900 900 900 2000 200 -k 1000 446``` 447 448### Touch Click Event 449Simulates a finger click at coordinates (dx, dy). 450 451**Command** 452```bash 453uinput -T -c <dx> <dy> [click interval] 454uinput --touch --click <dx> <dy> [click interval] 455 456The value of [click interval] can be set between 1 and 450 ms. 457``` 458 459**Example** 460```bash 461# Click at the coordinates (100, 100) using a finger. 462uinput -T -c 100 100 463``` 464 465### Touch Drag Event 466Simulates a finger touch drag event. 467 468**Command** 469```bash 470uinput -T -g <dx1> <dy1> <dx2> <dy2> [press time] [total time] 471uinput --touch --drag <dx1> <dy1> <dx2> <dy2> [press time] [total time] 472 473The value of [Press time] cannot be less than 500 ms. 474[total time] specifies the total time of the drag operation. The value of [total time] and [Press time] cannot be less than 500 ms. Otherwise, an error or invalid operation may occur. 475``` 476 477**Example** 478```bash 479# Use a finger to drag from coordinates (100, 150) to coordinates (500, 300) after 1100 ms. 480uinput -T -g 100 150 500 300 500 1100 481``` 482 483### Interval of Touch Events 484Sets the interval of touch events, in milliseconds. 485 486**Command** 487```bash 488uinput -T -i <time> 489uinput --touch --interval <time> 490``` 491 492**Example** 493```bash 494# Set the interval between the two touch events at coordinates (100,100) to 500 ms. 495uinput -S -c 100 100 -i 500 -c 100 100 496``` 497 498### Knuckle Touch Event 499Touches a screen with a single knuckle. 500 501**Command** 502```bash 503uinput -T -k -s <dx1> <dy1> <dx2> <dy2> [interval time] 504uinput --touch --knuckle --single <dx1> <dy1> <dx2> <dy2> [interval time] 505 506The value of [interval time] can be set between 1 ms and 250 ms. The default value is 200 ms. 507``` 508 509**Example** 510```bash 511# Set the interval between the knuckle touch events at coordinates (100, 100) and (100, 130) to 200 ms. 512uinput -T -k -s 100 100 100 130 513``` 514 515### Double-Knuckle Touch Event 516Touches a screen with two knuckles. 517 518**Command** 519```bash 520uinput -T -k -d <dx1> <dy1> <dx2> <dy2> [interval time] 521uinput --touch --knuckle --double <dx1> <dy1> <dx2> <dy2> [interval time] 522 523The value of [interval time] can be set between 1 ms and 250 ms. The default value is 200 ms. 524``` 525 526**Example** 527```bash 528# Set the interval between the double-knuckle touch events at coordinates (100, 100) and (100, 130) to 200 ms. 529uinput -T -k -d 100 100 100 130 530``` 531 532## Touchpad Events 533 534### Touchpad Pinch Event 535Simulates finger pinching on the touchpad. 536 537**Command** 538```bash 539uinput -P -p <dx> <dy> scalePercent 540uinput --touchpad --pinch <dx> <dy> scalePercent 541 542The value of scalePercent can be set between 0 and 500. If the value is less than 100, the image is zoomed out. If the value is greater than 100, the image is zoomed in. The value of dx must be greater than 0 and the value of dy must be greater than 200. In this case, only image zooming is supported. Before running this command, ensure that there is an image on the screen. 543``` 544 545**Example** 546```bash 547# Pinch the image. 548uinput -P -p 100 300 89 549``` 550 551### Touchpad Swipe Event 552Simulates the swiping and pinching on the touchpad. 553 554**Command** 555```bash 556uinput -P -s <startX> <startY> <endX> <endY> 557uinput --touchpad --swipe <startX> <startY> <endX> <endY> 558``` 559 560**Example** 561```bash 562# Swipe on the touchpad to view the Task View. 563uinput -P -s 100 1100 100 300 564``` 565