1# uinput 2 3uinput可模拟用户操作鼠标、键盘、触控板等设备,用于稳定性等压力测试。 4 5## 环境要求 6 7- 根据hdc命令行工具指导,完成[环境准备](hdc.md#环境准备)。 8 9- 正常连接设备。 10 11## uinput功能 12 13**用法** 14```bash 15uinput <option> <command> <arg> ... 16``` 17 18**支持能力** 19| 命令简写 | 命令全写 | 含义说明 | 20| -------- | -------- | -------- | 21| -M | --mouse | 注入鼠标事件。 | 22| -K | --keyboard | 注入键盘事件。 | 23| -S | --stylus | 注入触控笔事件。 | 24| -T | --touch | 注入触摸事件。 | 25| -P | --touchpad | 注入触控板事件。| 26| -? | --help | 帮助命令。 | 27 28> **说明:** 29> 30> 命令中与坐标相关的参数,单位均为[px(屏幕物理像素单位)](../reference/apis-arkui/arkui-ts/ts-pixel-units.md)。 31 32## 帮助命令 33 34显示uinput工具能够支持的命令信息。 35 36**命令** 37```bash 38uinput -? 39uinput --help 40``` 41 42**使用示例** 43```bash 44# 显示帮忙信息 45uinput -? 46 47# 执行结果 48sage: uinput <option> <command> <arg>... 49The option 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## 鼠标事件 63 64模拟鼠标移动、点击等事件。 65 66### 鼠标移动事件 67模拟鼠标移动到相对位置(dx, dy)。 68 69**命令** 70```bash 71uinput -M -m <dx> <dy> 72uinput --mouse --move <dx> <dy> 73``` 74 75**使用示例** 76```bash 77# 模拟鼠标移动到相对位置(100, 100)。 78uinput -M -m 100 100 79``` 80 81**扩展命令** 82```bash 83uinput -M -m <dx1> <dy1> <dx2> <dy2> [smooth time] --trace 84uinput --mouse --move <dx1> <dy1> <dx2> <dy2> [smooth time] --trace 85 86补充选项--trace,可以模拟鼠标移动相对位置及过程 87[smooth time]移动时间,默认值:1000ms,取值范围:1 ~ 15000ms。 88``` 89 90**使用示例** 91```bash 92# 模拟鼠标从(100, 100)花费1500ms移动到(200, 200)。 93uinput -M -m 100 100 200 200 1500 --trace 94``` 95 96### 鼠标按键按下事件 97模拟鼠标按下按键,与抬起事件使用。key:[键值定义说明](#鼠标按键) 98 99**命令** 100```bash 101uinput -M -d <key> 102uinput --mouse --down <key> 103``` 104 105### 鼠标按键抬起事件 106模拟鼠标按下按键,与按下事件使用。key:[键值定义说明](#鼠标按键) 107 108**命令** 109```bash 110uinput -M -u <key> 111uinput --mouse --up <key> 112``` 113 114**使用示例** 115```bash 116# 按下鼠标左键并抬起。 117uinput -M -d 0 -u 0 118``` 119 120### 鼠标按键单击事件 121模拟鼠标单击按键。key:[键值定义说明](#鼠标按键) 122 123**命令** 124```bash 125uinput -M -c <key> 126uinput --mouse --click <key> 127``` 128 129**使用示例** 130```bash 131# 单击鼠标左键。 132uinput -M -c 0 133``` 134 135### 双击鼠标按键事件 136模拟双击鼠标按键。id:[键值定义说明](#鼠标按键) 137 138**命令** 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 143[press time]按压时间,取值范围:1 ~ 300ms。 144[click interval time] 点击间隔时间,取值范围:1 ~ 450ms。 145设置间隔时间必须在取值范围内,否则操作结果可能产生错误或无效操作。 146``` 147 148**使用示例** 149```bash 150# 在(100, 150)这个位置双击鼠标左键。 151uinput -M -b 100 150 0 10 10 152``` 153 154### 鼠标滚轴滚动事件 155模拟鼠标滚轴向后滚动。 156 157**命令** 158```bash 159uinput -M -s <number> 160uinput --mouse --scroll <number> 161 162number鼠标滚动刻度数,一个刻度是15。 163``` 164 165**使用示例** 166```bash 167# 鼠标滚轴向后滚动三个刻度。 168uinput -M -s 45 169``` 170 171### 鼠标拖拽事件 172模拟鼠标拖拽。 173 174**命令** 175```bash 176uinput -M -g <dx1> <dy1> <dx2> <dy2> [total time] 177uinput --mouse --drag <dx1> <dy1> <dx2> <dy2> [total time] 178 179[total time]可选参数,默认值为3000ms,取值范围:3000 ~ 15000ms。 180``` 181 182**使用示例** 183```bash 184# 模拟按下鼠标左键从(100, 150)在指定时间拖动到(500, 300)后释放鼠标左键。 185uinput -M -g 100 150 500 300 186``` 187 188### 设置鼠标事件间隔 189设置鼠标事件以毫秒为单位的程序间隔。 190 191**命令** 192```bash 193uinput -M -i <time> 194uinput --mouse --interval <time> 195``` 196 197**使用示例** 198```bash 199# 单击鼠标左键间隔500ms后再次单击鼠标左键。 200uinput -M -c 0 -i 500 -c 0 201``` 202 203### 鼠标按键 204| key | 含义说明 | 205| -------- | -------- | 206| 0 | 鼠标左键 | 207| 1 | 鼠标右键 | 208| 2 | 鼠标中键 | 209| 3 | 鼠标侧边键 | 210| 4 | 鼠标扩展键 | 211| 5 | 鼠标前进键 | 212| 6 | 鼠标后退键 | 213| 7 | 鼠标任务键 | 214 215## 键盘事件 216 217模拟编辑框键盘按键输入事件。 218 219### 键盘按键按下事件 220模拟键盘按下按键,与抬起事件使用。key:[键值定义说明](../reference/apis-input-kit/js-apis-keycode.md)。 221 222**命令** 223```bash 224uinput -K -d <key> 225uinput --keyboard --down <key> 226``` 227 228### 键盘按键抬起事件 229模拟键盘抬起按键,与按下事件使用。key:[键值定义说明](../reference/apis-input-kit/js-apis-keycode.md)。 230 231**命令** 232```bash 233uinput -K -u <key> 234uinput --keyboard --up <key> 235``` 236 237**使用示例** 238```bash 239# 按下"a"键并抬起。 240uinput -K -d 2017 -u 2017 241``` 242 243### 键盘按键长按事件 244模拟键盘按下一个按键并保持设定的时长。key:[键值定义说明](../reference/apis-input-kit/js-apis-keycode.md)。 245 246**命令** 247```bash 248uinput -K -l <key> [long press time] 249uinput --keyboard --long_press <key> [long press time] 250``` 251 252**使用示例** 253```bash 254# 按下"a"键并保持100ms后抬起。 255uinput -K -l 2017 100 256``` 257 258### 键盘按键持续输入事件 259模拟键盘按下一个按键并在设定的时长内持续输入。key:[键值定义说明](../reference/apis-input-kit/js-apis-keycode.md)。 260 261**命令** 262```bash 263uinput -K -r <key> [repeat output time] 264uinput --keyboard --repeat <key> [repeat output time] 265``` 266 267**使用示例** 268```bash 269# 按下"a"键并在100ms内重复输入。 270uinput -K -r 2017 100 271``` 272 273### 设置键盘事件间隔 274设置键盘事件以毫秒为单位的程序间隔。 275 276**命令** 277```bash 278uinput -K -i <time> 279uinput --keyboard --interval <time> 280``` 281 282**使用示例** 283```bash 284# 按下键盘‘a’键间隔500ms后释放。 285uinput -K -d 2017 -i 500 -u 2017 286``` 287 288### 键盘文本输入事件 289模拟键盘输入文本。不支持与其他commands组合使用。只支持ASCLL字符,最大支持输入字符2000个。 290 291**命令** 292```bash 293uinput -K -t <text> 294uinput --keyboard --text <text> 295``` 296 297**使用示例** 298```bash 299# 在编辑框输入一段文本"123" 300uinput -K -t 123 301``` 302 303## 触控笔事件 304 305模拟触控笔点击、滑动等事件。 306 307### 触控笔按下事件 308模拟触控笔在(dx dy)按下,与up配合使用。 309 310**命令** 311```bash 312uinput -S -d <dx> <dy> 313uinput --stylus --down <dx> <dy> 314``` 315 316### 触控笔抬起事件 317模拟触控笔在(dx dy)抬起,与down配合使用。 318 319**命令** 320```bash 321uinput -S -u <dx> <dy> 322uinput --stylus --up <dx> <dy> 323``` 324 325**使用示例** 326```bash 327# 在(100, 100)位置按下并抬起。 328uinput -S -d 100 100 -u 100 100 329``` 330 331### 触控笔移动事件 332模拟触控笔从(dx1, dy1)按下在smooth time(毫秒)移动到(dx2, dy2)后抬起。 333 334**命令** 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 339[smooth time]可选参数,默认值为1000ms,取值范围:1 ~ 15000ms。 340[-k keep time]可选参数,默认值为0ms,取值范围:0 ~ 60000ms。 341``` 342 343**使用示例** 344```bash 345# 触控笔从(100, 100)按下花费1000ms移动到(200, 200)后抬起。 346uinput -S -m 100 100 200 200 1000 -k 1000 347``` 348 349### 触控笔单击事件 350模拟触控笔在(dx, dy)位置单击。 351 352**命令** 353```bash 354uinput -S -c <dx> <dy> [click interval] 355uinput --stylus --click <dx> <dy> [click interval] 356 357[click interval] 点击间隔时间,取值范围:1 ~ 450ms。 358``` 359 360**使用示例** 361```bash 362# 触控笔在(100, 100)位置单击。 363uinput -S -c 100 100 364``` 365 366### 触控笔拖拽事件 367模拟触控笔拖拽事件。 368 369**命令** 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 374[Press time]按压时间,不能少于500ms。 375[total time]拖动时间,[total time] - [Press time]不能少于500ms,否则操作结果可能产生错误或无效操作。 376``` 377 378**使用示例** 379```bash 380# 模拟触控笔按下从(100, 150)在1100ms拖动到(500, 300)后释放。 381uinput -S -g 100 150 500 300 500 1100 382``` 383 384### 设置触控笔事件间隔 385设置触控笔事件以毫秒为单位的程序间隔。 386 387**命令** 388```bash 389uinput -S -i <time> 390uinput --stylus --interval <time> 391``` 392 393**使用示例** 394```bash 395# 单击(100, 100)位置后,间隔500ms后再次单击(100, 100)位置。 396uinput -S -c 100 100 -i 500 -c 100 100 397``` 398 399## 触摸事件 400 401模拟手指触摸点击、滑动等事件。 402 403### 触摸按下事件 404模拟手指触摸在(dx dy)按下,与up配合使用。 405 406**命令** 407```bash 408uinput -T -d <dx> <dy> 409uinput --touch --down <dx> <dy> 410``` 411 412### 触摸抬起事件 413模拟手指触摸在(dx dy)抬起,与down配合使用。 414 415**命令** 416```bash 417uinput -T -u <dx> <dy> 418uinput --touch --up <dx> <dy> 419``` 420 421**使用示例** 422```bash 423# 在(100, 100)位置按下并抬起。 424uinput -T -d 100 100 -u 100 100 425``` 426 427### 触摸移动事件 428模拟手指触摸从(dx1, dy1)按下在smooth time(毫秒)移动到(dx2, dy2)后抬起。最多支持三指同时移动。 429 430**命令** 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 435[-k keep time]可选参数,默认值为0ms,取值范围:0 ~ 60000ms。 436[smooth time]可选参数,默认值为1000ms,取值范围:1 ~ 15000ms。 437``` 438 439**使用示例** 440```bash 441# 手指触摸从(100, 100)按下花费1000ms移动到(200, 200)后抬起。 442uinput -T -m 100 100 200 200 1000 -k 1000 443 444# 三指滑动,第一根手指触摸按下从(300,900)移动到(300,2000),第二根手指触摸按下从(600,900)移动到(600,2000),第三根手指触摸按下从(900,900)移动到(900,2000),移动总时长为200ms,移动结束后手指在屏幕停顿1000m后再抬起。 445uinput -T -m 300 900 300 2000 600 900 600 2000 900 900 900 2000 200 -k 1000 446``` 447 448### 触摸单击事件 449模拟手指触摸在(dx, dy)位置单击。 450 451**命令** 452```bash 453uinput -T -c <dx> <dy> [click interval] 454uinput --touch --click <dx> <dy> [click interval] 455 456[click interval] 点击间隔时间,取值范围:1 ~ 450ms。 457``` 458 459**使用示例** 460```bash 461# 手指在触摸屏(100, 100)位置单击。 462uinput -T -c 100 100 463``` 464 465### 触摸拖拽事件 466模拟手指触摸拖拽事件。 467 468**命令** 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 473[Press time]按压时间,不能少于500ms。 474[total time]拖动时间,[total time] - [Press time]不能少于500ms,否则操作结果可能产生错误或无效操作。 475``` 476 477**使用示例** 478```bash 479# 模拟手指按下从(100, 150)在1100ms拖动到(500, 300)后释放。 480uinput -T -g 100 150 500 300 500 1100 481``` 482 483### 设置触摸事件间隔 484设置触摸事件以毫秒为单位的程序间隔。 485 486**命令** 487```bash 488uinput -T -i <time> 489uinput --touch --interval <time> 490``` 491 492**使用示例** 493```bash 494# 手指单击(100, 100)位置后,间隔500ms后再次单击(100, 100)位置。 495uinput -S -c 100 100 -i 500 -c 100 100 496``` 497 498### 触摸单指关节双击事件 499模拟触摸屏单指关节双击。 500 501**命令** 502```bash 503uinput -T -k -s <dx1> <dy1> <dx2> <dy2> [interval time] 504uinput --touch --knuckle --single <dx1> <dy1> <dx2> <dy2> [interval time] 505 506[interval time]间隙时间:默认值200ms,取值范围:1 ~ 250ms。 507``` 508 509**使用示例** 510```bash 511# 单指关节在(100, 100)、(100, 130)位置间隔200ms敲击。 512uinput -T -k -s 100 100 100 130 513``` 514 515### 触摸指双关节双击事件 516模拟触摸屏双指关节双击。 517 518**命令** 519```bash 520uinput -T -k -d <dx1> <dy1> <dx2> <dy2> [interval time] 521uinput --touch --knuckle --double <dx1> <dy1> <dx2> <dy2> [interval time] 522 523[interval time]间隙时间:默认值200ms,取值范围:1 ~ 250ms。 524``` 525 526**使用示例** 527```bash 528# 双指关节在(100, 100)、(100, 130)位置间隔200ms敲击。 529uinput -T -k -d 100 100 100 130 530``` 531 532## 触控板事件 533 534### 触控板捏合事件 535模拟触控板手指捏合。 536 537**命令** 538```bash 539uinput -P -p <dx> <dy> scalePercent 540uinput --touchpad --pinch <dx> <dy> scalePercent 541 542scalePercent:收缩百分比,取值范围:0~500。小于100是缩小,大于100是放大。设置时要求dx大于0,dy大于200。此场景只支持图片缩放,调用该命令时,确保桌面上有一张图片。 543``` 544 545**使用示例** 546```bash 547# 手指捏合图片。 548uinput -P -p 100 300 89 549``` 550 551### 触控板滑动事件 552模拟触控板滑动捏合。 553 554**命令** 555```bash 556uinput -P -s <startX> <startY> <endX> <endY> 557uinput --touchpad --swipe <startX> <startY> <endX> <endY> 558``` 559 560**使用示例** 561```bash 562# 在触控板滑动手指,可以看到后台多任务视图。 563uinput -P -s 100 1100 100 300 564```