September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
30
Task/Mouse-position/AppleScript/mouse-position-1.applescript
Normal file
30
Task/Mouse-position/AppleScript/mouse-position-1.applescript
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
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
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
-- Cursor position relative to active window
|
||||
[Cx - Wx as integer, Cy - Wy as integer]
|
||||
8
Task/Mouse-position/Common-Lisp/mouse-position.lisp
Normal file
8
Task/Mouse-position/Common-Lisp/mouse-position.lisp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(ql:quickload "ltk")
|
||||
(in-package :ltk-user)
|
||||
(defun motion (event)
|
||||
(format t "~a x position is ~a~&" event (event-x event)))
|
||||
|
||||
(with-ltk ()
|
||||
;; create a small window. Enter the mouse to see lots of events.
|
||||
(bind *tk* "<Motion>" #'motion))
|
||||
35
Task/Mouse-position/Go/mouse-position.go
Normal file
35
Task/Mouse-position/Go/mouse-position.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/go-vgo/robotgo"
|
||||
)
|
||||
|
||||
func isInside(x, y, w, h, mx, my int) bool {
|
||||
rx := x + w - 1
|
||||
ry := y + h - 1
|
||||
return mx >= x && mx <= rx && my >= y && my <= ry
|
||||
}
|
||||
|
||||
func main() {
|
||||
name := "gedit" // say
|
||||
fpid, err := robotgo.FindIds(name)
|
||||
if err == nil && len(fpid) > 0 {
|
||||
pid := fpid[0]
|
||||
robotgo.ActivePID(pid) // make gedit active window
|
||||
x, y, w, h := robotgo.GetBounds(pid)
|
||||
fmt.Printf("The active window's top left corner is at (%d, %d)\n", x, y)
|
||||
fmt.Printf("Its width is %d and its height is %d\n", w, h)
|
||||
mx, my := robotgo.GetMousePos()
|
||||
fmt.Printf("The screen location of the mouse cursor is (%d, %d)\n", mx, my)
|
||||
if !isInside(x, y, w, h, mx, my) {
|
||||
fmt.Println("The mouse cursor is outside the active window")
|
||||
} else {
|
||||
wx := mx - x
|
||||
wy := my - y
|
||||
fmt.Printf("The window location of the mouse cursor is (%d, %d)\n", wx, wy)
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Problem when finding PID(s) of", name)
|
||||
}
|
||||
}
|
||||
15
Task/Mouse-position/Julia/mouse-position.julia
Normal file
15
Task/Mouse-position/Julia/mouse-position.julia
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using Gtk
|
||||
|
||||
const win = GtkWindow("Get Mouse Position", 600, 800)
|
||||
const butn = GtkButton("Click Me Somewhere")
|
||||
push!(win, butn)
|
||||
|
||||
callback(b, evt) = set_gtk_property!(win, :title, "Mouse Position: X is $(evt.x), Y is $(evt.y)")
|
||||
signal_connect(callback, butn, "button-press-event")
|
||||
|
||||
showall(win)
|
||||
|
||||
c = Condition()
|
||||
endit(w) = notify(c)
|
||||
signal_connect(endit, win, :destroy)
|
||||
wait(c)
|
||||
22
Task/Mouse-position/Perl-6/mouse-position-2.pl6
Normal file
22
Task/Mouse-position/Perl-6/mouse-position-2.pl6
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use X11::libxdo;
|
||||
my $xdo = Xdo.new;
|
||||
|
||||
my ($dw, $dh) = $xdo.get-desktop-dimensions( 0 );
|
||||
|
||||
sleep .25;
|
||||
|
||||
for ^$dw -> $mx {
|
||||
my $my = (($mx / $dh * τ).sin * 500).abs.Int + 200;
|
||||
$xdo.move-mouse( $mx, $my, 0 );
|
||||
my ($x, $y, $window-id, $screen) = $xdo.get-mouse-info;
|
||||
my $name = (try $xdo.get-window-name($window-id) if $window-id)
|
||||
// 'No name set';
|
||||
|
||||
my $line = "Mouse location: x=$x : y=$y\nWindow under mouse:\nWindow ID: " ~
|
||||
$window-id ~ "\nWindow name: " ~ $name ~ "\nScreen #: $screen";
|
||||
|
||||
print "\e[H\e[J", $line;
|
||||
sleep .001;
|
||||
}
|
||||
|
||||
say '';
|
||||
Loading…
Add table
Add a link
Reference in a new issue