此代碼用於單擊屏幕上的特定位置,但是如何單擊光標的座標?AppleScript單擊鼠標位置
tell application "System Events"
click at {10, 10}
end tell
此代碼用於單擊屏幕上的特定位置,但是如何單擊光標的座標?AppleScript單擊鼠標位置
tell application "System Events"
click at {10, 10}
end tell
你一定要抓住AppleScript工具箱。它具有腳本命令來獲取鼠標位置和鼠標點擊。 AppleScript Toolbox is a scripting addition/AppleScript-plugin (a.k.a. 「OSAX」) providing commands not available in regular AppleScript。
下面的例子與python在applescript中,python是生活在你的系統自然,沒有安裝計劃。
set x to 30
set y to 5
set l to 50 -- click same location 50 times
do shell script "
/usr/bin/python <<END
import sys
import time
from Quartz.CoreGraphics import *
def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(posx,posy):
mouseEvent(kCGEventMouseMoved, posx,posy);
def mouseclick(posx,posy):
mouseEvent(kCGEventLeftMouseDown, posx,posy);
mouseEvent(kCGEventLeftMouseUp, posx,posy);
ourEvent = CGEventCreate(None);
currentpos=CGEventGetLocation(ourEvent); # Save current mouse position
for x in range(0, " & l & "):
mouseclick(" & x & "," & y & ");
mousemove(int(currentpos.x),int(currentpos.y)); # Restore mouse position
END"
你好,下面是一個例子,在python中的applescript中,python自然地生活在你的系統中,沒有計劃安裝。 – deek5
您還可以使用applescrit命令工具cliclick
dowload https://github.com/BlueM/cliclick
unzip cliclick-master.zip
in a Terminal
cd /Users/yourname/Downloads/cliclick-master
make
now you have in /Users/yourname/Downloads/cliclick-master/
cliclick , command tool for using a mouse in applescript with do shell script
copy cliclick in /usr/local/bin folder
in a Terminal
cp -f /Users/yourname/Downloads/cliclick-master/cliclick /usr/local/bin/
in applescript for example
do shell script "/usr/local/bin/cliclick " & quoted form of "c:12,34"
will click at the point with x coordinate
12 and y coordinate 34.
in a Terminal for LIST OF COMMANDS
cliclick -h
LIST OF COMMANDS
c:x,y Will CLICK at the point with the given coordinates.
Example: 「c:12,34」 will click at the point with x coordinate
12 and y coordinate 34. Instead of x and y values, you may
also use 「.」, which means: the current position. Using 「.」 is
equivalent to using relative zero values 「c:+0,+0」.
dc:x,y Will DOUBLE-CLICK at the point with the given coordinates.
Example: 「dc:12,34」 will double-click at the point with x
coordinate 12 and y coordinate 34. Instead of x and y values,
you may also use 「.」, which means: the current position.
dd:x,y Will press down to START A DRAG at the given coordinates.
Example: 「dd:12,34」 will press down at the point with x
coordinate 12 and y coordinate 34. Instead of x and y values,
you may also use 「.」, which means: the current position.
du:x,y Will release to END A DRAG at the given coordinates.
Example: 「du:112,134」 will release at the point with x
coordinate 112 and y coordinate 134.
kd:keys Will trigger a KEY DOWN event for a comma-separated list of
modifier keys. Possible keys are:
「alt」, 「cmd」, 「ctrl」, 「fn」, 「shift」
Example: 「kd:cmd,alt」 will press the command key and the
option key (and will keep them down until you release them
with another command)
kp:key Will emulate PRESSING A KEY (key down + key up). Possible keys are:
「arrow-down」, 「arrow-left」, 「arrow-right」, 「arrow-up」, 「delete」, 「end」,
「esc」, 「f1」, 「f2」, 「f3」, 「f4」, 「f5」, 「f6」, 「f7」, 「f8」, 「f9」, 「f10」, 「f11」,
「f12」, 「f13」, 「f14」, 「f15」, 「f16」, 「fwd-delete」, 「help」, 「home」, 「mute」,
「page-down」, 「page-up」, 「return」, 「space」, 「tab」, 「volume-down」, 「volume-up」
Example: 「kp:return」 will hit the return key.
ku:keys Will trigger a KEY UP event for a comma-separated list of
modifier keys. Possible keys are:
「alt」, 「cmd」, 「ctrl」, 「fn」, 「shift」
Example: 「ku:cmd,ctrl」 will release the command key and the
control key (which will only have an effect if you performed
a 「key down」 before)
m:x,y Will MOVE the mouse to the point with the given coordinates.
Example: 「m:12,34」 will move the mouse to the point with
x coordinate 12 and y coordinate 34.
p[:str] Will PRINT the given string. If the string is 「.」, the
current MOUSE POSITION is printed. As a convenience, you can skip
the string completely and just write 「p」 to get the current position.
Example: 「p:.」 or 「p」 will print the current mouse position
Example: 「p:'Hello world'」 will print 「Hello world」
tc:x,y Will TRIPLE-CLICK at the point with the given coordinates.
Example: 「tc:12,34」 will triple-click at the point with x
coordinate 12 and y coordinate 34. Instead of x and y values,
you may also use 「.」, which means: the current position.
t:text Will emulate typing the given text into the frontmost application.
If the text includes space(s), it must be enclosed in quotes.
Example: 「type:Test」 will type 「Test」
Example: 「type:'Viele Grüße'」 will type 「Viele Grüße」
w:ms Will WAIT/PAUSE for the given number of milliseconds.
Example: 「w:500」 will pause command execution for half a second
版本3.0.3,2014年10月29日發佈 作者:CarstenBlüm,<[email protected]> 貢獻者名單:https://github.com/BlueM/cliclick/graphs/contributors 網站:www。 bluem.net/jump/cliclick/ – deek5
我有完全正確的,現在同樣的問題。有沒有辦法'獲得'鼠標的座標? – Shuri2060
目前我能找到的最好的是這個:http://www.hamsoftengineering.com/codesharing/MouseTools/MouseTools.html – Shuri2060