有没有办法做到这一点,没有任何程序或脚本? (也许通过osascript?)如何通过mac终端模拟鼠标点击?
6
A
回答
1
嘿。 我有这个相同的问题,我不确定这是你想要的,但它可以让你将鼠标移动到屏幕上给定的坐标并执行一次点击。你需要英特尔,但我没有,所以我无法使用它,但我会给你任何你可能需要的帮助。链接:http://hints.macworld.com/article.php?story=2008051406323031
23
您可以使用Applescript自动点击鼠标。
tell application "System Events"
tell application process "Application_Name"
key code 53
delay 1
click (click at {1800, 1200})
end tell
end tell
如果你想在浏览器窗口中单击您可以使用AppleScript的使用Javascript
tell application "safari"
activate
do JavaScript "document.getElementById('element').click();"
end tell
纯粹通过终端的帮助下,你可以创建一个名称的文本文件click.m
或任何你喜欢的名字,请用以下代码保存:
// File:
// click.m
//
// Compile with:
// gcc -o click click.m -framework ApplicationServices -framework Foundation
//
// Usage:
// ./click -x pixels -y pixels
// At the given coordinates it will click and release.
//
// From http://hints.macworld.com/article.php?story=2008051406323031
#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSUserDefaults *args = [NSUserDefaults standardUserDefaults];
int x = [args integerForKey:@"x"];
int y = [args integerForKey:@"y"];
CGPoint pt;
pt.x = x;
pt.y = y;
CGPostMouseEvent(pt, 1, 1, 1);
CGPostMouseEvent(pt, 1, 1, 0);
[pool release];
return 0;
}
然后编译按指示:
gcc -o click click.m -framework ApplicationServices -framework Foundation
,并将其移动到相应的文件夹,方便
sudo mv click /usr/bin
sudo chmod +x /usr/bin/click
,现在你可以运行一个简单的终端命令来操纵鼠标
click -x [coord] -y [coord]
注意:更多彻底的代码示例已经由Jardel Weyrich提供,here和John Dorian提供了用Java编写的很好的解决方案,here
相关问题
- 1. 在Mac上模拟鼠标点击
- 2. 如何模拟鼠标点击事件
- 3. 如何模拟鼠标点击?
- 4. 如何模拟鼠标点击?
- 5. 模拟鼠标点击QWebEngineView
- 6. 模拟鼠标点击motionevents
- 7. 模拟鼠标点击
- 8. 模拟鼠标点击AS3
- 9. 通过模拟点击
- 10. 如何模拟鼠标移动和鼠标单击使用C或C++的Mac
- 11. 在MSPaint中模拟鼠标点击
- 12. Linux - 用Python模拟鼠标点击
- 13. 模拟鼠标点击下拉菜单
- 14. 模拟鼠标点击服务
- 15. 模拟真实的鼠标点击
- 16. 在R中模拟鼠标点击
- 17. 模拟鼠标点击侧按钮
- 18. 模拟鼠标点击板内(JPanel)
- 19. 试图模拟鼠标点击/拖动
- 20. 在jQuery中模拟鼠标点击
- 21. 模拟移位鼠标点击
- 22. 模拟Python上的鼠标点击
- 23. C++鼠标点击模拟代码
- 24. 鼠标点击模拟在JavaScript
- 25. 模拟鼠标点击背景表格
- 26. 在NSWindow中模拟鼠标点击
- 27. InkCanvas:如何通过点击鼠标右键点击擦除
- 28. 如何让终端编对鼠标点击作出反应
- 29. 如何让终端模拟器发送点击拖动消息?
- 30. 通过终端降低透明度在Mac中通过终端
+1优秀的答案!工作很好。 – 2014-11-01 08:21:43
你是一个巫师吗? – paulwal222 2015-06-14 17:04:59