September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View 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

View file

@ -0,0 +1,2 @@
-- Cursor position relative to active window
[Cx - Wx as integer, Cy - Wy as integer]

View 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))

View 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)
}
}

View 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)

View 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 '';