简体   繁体   English

python - 如何在不移动鼠标的情况下执行点击?

[英]How can I perform a click without moving the mouse in python?

I am trying to make a program that can control the mouse to perform actions in an instance of bluestacks (for those who aren't familiar with bluestacks, an instance of bluestacks is basically a second open bluestacks that can run as the same time as another bluestacks instance).我正在尝试制作一个可以控制鼠标在bluestacks实例中执行操作的程序(对于那些不熟悉bluestacks的人来说,bluestacks的实例基本上是第二个打开的bluestacks,可以与另一个同时运行bluestacks 实例)。 I managed to get the script working with PyAutoGUI but I am forced to use the MoveTo command that moves the mouse to an X,Y position.我设法让脚本与 PyAutoGUI 一起工作,但我被迫使用 MoveTo 命令将鼠标移动到 X、Y 位置。 My issue is that when trying to run multiple instances & scripts at once, if a click from different scripts at the same time within a short range of time, one of the clicks "bugs out" or simply doesn't happen, which stalls one of the instance scripts until I manually restart it.我的问题是,当尝试一次运行多个实例和脚本时,如果在很短的时间内同时从不同的脚本单击,其中一个单击“错误”或根本没有发生,这会导致一个实例脚本,直到我手动重新启动它。 Does anyone have a suggestion on how I can make the script "click" in a position of the screen without the mouse actually moving?有没有人对如何让脚本在屏幕的某个位置“单击”而不实际移动鼠标有任何建议?

EDIT: I am aware of PyAutoIt but do not believe it would work since I am running multiple instances of the same program and not different programs编辑:我知道 PyAutoIt 但不相信它会起作用,因为我正在运行同一程序的多个实例而不是不同的程序

The best approach is to install Android debug bridge (ADB) on your system then enable ADB debugging for each Bluestacks instance.最好的方法是在您的系统上安装 Android 调试桥 (ADB),然后为每个 Bluestacks 实例启用 ADB 调试。 Now you can use ADB to send commands directly to the exact emulator of your choice and you can do it in parallel because all commands are guaranteed to run on the specified device via the device ID.现在,您可以使用 ADB 将命令直接发送到您选择的确切模拟器,并且可以并行执行,因为所有命令都保证通过设备 ID 在指定设备上运行。

adb -s <deivce_id> shell input tap xy where x & y are the coordinates on the screen. adb -s <deivce_id> shell input tap xy其中 x & y 是屏幕上的坐标。

You can, also, do the same thing with Appium but it will still require ADB and will be more involved - however, if you are looking to build something more than just a simple script you should really be looking at Appium.你也可以用 Appium 做同样的事情,但它仍然需要 ADB 并且会更多地参与 - 但是,如果你想构建的不仅仅是一个简单的脚本,你真的应该看看 Appium。

There is a whole lot more you can do with ADB - I have a comprehensive ADB tutorial as well if you wonder what sort of stuff you can do with it other then clicking in on x, y cords.您可以使用 ADB 做更多事情——如果您想知道除了点击 x、y 线之外还可以用它做什么类型的事情,我也有一个全面的 ADB 教程

I also have very comprehensive tutorial playlists for Appium from beginner to advanced framework design .我还有非常全面的 Appium 教程播放列表,从初学者高级框架设计

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM