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