Mouse position: Difference between revisions

AppleScript/AppleScriptObjC
(Added Go)
(AppleScript/AppleScriptObjC)
Line 143:
Gtk.Main.Main;
end Tell_Mouse;</lang>
 
=={{header|AppleScript}}==
The window can be any window on the system, externally created or otherwise, provided it can acquire focus. Mouse location is retrieved with help from AppleScriptObjC.
 
<lang AppleScript>use application "System Events"
 
property process : a reference to (first process whose frontmost = true)
property window : a reference to front window of my process
 
 
set [Wx, Wy] to my window's position
set [Cx, Cy] to {x, y} of the mouse's coordinates()
 
 
script mouse
use framework "Foundation"
property this : a reference to current application
property NSEvent : a reference to NSEvent of this
property NSScreen : a reference to NSScreen of this
on coordinates()
-- Screen dimensions
set display to NSDeviceSize of deviceDescription() ¬
of item 1 of NSScreen's screens() as record
-- Mouse position relative to bottom-left of screen
set mouseLoc to (NSEvent's mouseLocation as record)
-- Flip mouse y-coordinate so it's relative to top of screen
set mouseLoc's y to (display's height) - (mouseLoc's y)
mouseLoc
end coordinates
end script
</lang>
 
{{out}}<lang AppleScript>-- Cursor position relative to active window
[Cx - Wx as integer, Cy - Wy as integer]</lang>
 
=={{header|AutoHotkey}}==
Anonymous user