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