This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1 @@
Get the current location of the mouse cursor relative to the active window. Please specify if the window may be externally created.

View file

@ -0,0 +1,4 @@
---
category:
- Testing
note: GUI

View file

@ -0,0 +1,67 @@
with GLib; use GLib;
with Gtk.Button; use Gtk.Button;
with Gtk.Label; use Gtk.Label;
with Gtk.Window; use Gtk.Window;
with Gtk.Widget; use Gtk.Widget;
with Gtk.Table; use Gtk.Table;
with Gtk.Handlers;
with Gtk.Main;
procedure Tell_Mouse is
Window : Gtk_Window;
Grid : Gtk_Table;
Button : Gtk_Button;
Label : Gtk_Label;
package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
package Return_Handlers is
new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);
function Delete_Event (Widget : access Gtk_Widget_Record'Class)
return Boolean is
begin
return False;
end Delete_Event;
procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
begin
Gtk.Main.Main_Quit;
end Destroy;
procedure Clicked (Widget : access Gtk_Widget_Record'Class) is
X, Y : GInt;
begin
Get_Pointer (Window, X, Y);
Set_Text (Label, "At" & GInt'Image (X) & GInt'Image (Y));
end Clicked;
begin
Gtk.Main.Init;
Gtk.Window.Gtk_New (Window);
Gtk_New (Grid, 1, 2, False);
Add (Window, Grid);
Gtk_New (Label);
Attach (Grid, Label, 0, 1, 0, 1);
Gtk_New (Button, "Click me");
Attach (Grid, Button, 0, 1, 1, 2);
Return_Handlers.Connect
( Window,
"delete_event",
Return_Handlers.To_Marshaller (Delete_Event'Access)
);
Handlers.Connect
( Window,
"destroy",
Handlers.To_Marshaller (Destroy'Access)
);
Handlers.Connect
( Button,
"clicked",
Handlers.To_Marshaller (Clicked'Access)
);
Show_All (Grid);
Show (Window);
Gtk.Main.Main;
end Tell_Mouse;

View file

@ -0,0 +1,5 @@
#i:: ; (Optional) Assigns a hotkey to display window info, Windows+i
MouseGetPos, x, y ; Gets x/y pos relative to active window
WinGetActiveTitle, WinTitle ; Gets active window title
Traytip, Mouse position, x: %x%`ny: %y%`rWindow: %WinTitle%, 4 ; Displays the info as a Traytip for 4 seconds
return

View file

@ -0,0 +1,2 @@
MOUSE xmouse%, ymouse%, buttons%
PRINT xmouse%, ymouse%

View file

@ -0,0 +1,37 @@
#include <stdio.h>
#include <X11/Xlib.h>
int main()
{
Display *d;
Window inwin; /* root window the pointer is in */
Window inchildwin; /* child win the pointer is in */
int rootx, rooty; /* relative to the "root" window; we are not interested in these,
but we can't pass NULL */
int childx, childy; /* the values we are interested in */
Atom atom_type_prop; /* not interested */
int actual_format; /* should be 32 after the call */
unsigned int mask; /* status of the buttons */
unsigned long n_items, bytes_after_ret;
Window *props; /* since we are interested just in the first value, which is
a Window id */
/* default DISPLAY */
d = XOpenDisplay(NULL);
/* ask for active window (no error check); the client must be freedesktop
compliant */
(void)XGetWindowProperty(d, DefaultRootWindow(d),
XInternAtom(d, "_NET_ACTIVE_WINDOW", True),
0, 1, False, AnyPropertyType,
&atom_type_prop, &actual_format,
&n_items, &bytes_after_ret, (unsigned char**)&props);
XQueryPointer(d, props[0], &inwin, &inchildwin,
&rootx, &rooty, &childx, &childy, &mask);
printf("relative to active window: %d,%d\n", childx, childy);
XFree(props); /* free mem */
(void)XCloseDisplay(d); /* and close the display */
return 0;
}

View file

@ -0,0 +1 @@
(let [point (.. java.awt.MouseInfo getPointerInfo getLocation)] [(.getX point) (.getY point)])

View file

@ -0,0 +1,5 @@
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
lblMousePosition.Caption := ('X:' + IntToStr(X) + ', Y:' + IntToStr(Y));
end;

View file

@ -0,0 +1,15 @@
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils, Controls, Windows;
var
MyMouse : TMouse;
begin
MyMouse := TMouse.Create;
While True do
begin
WriteLn('(X, y) = (' + inttostr(TPoint(MyMouse.CursorPos).x) + ',' + inttostr(TPoint(MyMouse.CursorPos).y) + ')');
sleep(300);
end
end.

View file

@ -0,0 +1,13 @@
: replace-text ( button text -- )
[ drop children>> pop drop ] [ >label add-gadget drop ] 2bi;
: present-locations ( loc1 loc2 -- string )
[
first2 [ number>string ] bi@ "," glue
] bi@ ";" glue ;
: example ( -- ) "click me"
[
dup hand-rel ! location relative to the button
hand-loc get ! location relative to the window
present-locations replace-text
]
<border-button> gadget. ;

View file

@ -0,0 +1,4 @@
PUBLIC SUB Form1_MouseMove()
PRINT mouse.X
PRINT Mouse.Y
END

View file

@ -0,0 +1,5 @@
1.upto(5) {
Thread.sleep(1000)
def p = java.awt.MouseInfo.pointerInfo.location
println "${it}: x=${p.@x} y=${p.@y}"
}

View file

@ -0,0 +1,7 @@
WINDOW(WINdowhandle=handle)
AXIS(WINdowhandle=handle, MouSeCall=Mouse_Callback, MouSeX=X, MouSeY=Y)
END
SUBROUTINE Mouse_Callback()
WRITE(Messagebox, Name) X, Y
END

View file

@ -0,0 +1,5 @@
until *Pending() > 0 & Event() == "q" do { # loop until there is something to do
px := WAttrib("pointerx")
py := WAttrib("pointery")
# do whatever is needed
WDelay(5) # wait and share processor

View file

@ -0,0 +1 @@
Point mouseLocation = MouseInfo.getPointerInfo().getLocation();

View file

@ -0,0 +1,3 @@
document.addEventListener('mousemove', function(e){
var position = { x: e.clientX, y: e.clientY }
}

View file

@ -0,0 +1,38 @@
nomainwin
UpperLeftX = DisplayWidth-WindowWidth
UpperLeftY = DisplayHeight-WindowHeight
struct point, x as long, y as long
stylebits #main.st ,0,0,_WS_EX_STATICEDGE,0
statictext #main.st "",16,16,100,26
stylebits #main ,0,0,_WS_EX_TOPMOST,0
open "move your mouse" for window_nf as #main
#main "trapclose [quit]"
timer 100, [mm]
wait
[mm]
CallDll #user32, "GetForegroundWindow", WndHandle as uLong
#main.st CursorPos$(WndHandle)
wait
[quit]
close #main
end
function CursorPos$(handle)
Calldll #user32, "GetCursorPos",_
point as struct,_
result as long
Calldll #user32, "ScreenToClient",_
handle As Ulong,_
point As struct,_
result as long
x = point.x.struct
y = point.y.struct
CursorPos$=x; ",";y
end function

View file

@ -0,0 +1 @@
show mousepos ; [-250 250]

View file

@ -0,0 +1 @@
get(0,'PointerLocation')

View file

@ -0,0 +1 @@
MousePosition["WindowAbsolute"]

View file

@ -0,0 +1,13 @@
use SDL;
use SDL::Events;
use SDLx::App;
my $app = SDLx::App->new;
$app->add_event_handler( sub {
my $event = shift;
if( $event->type == SDL_MOUSEMOTION ) {
printf( "x=%d y=%d\n", $event->motion_x, $event->motion_y );
$app->stop
}
} );
$app->run;

View file

@ -0,0 +1,12 @@
(de mousePosition ()
(prog2
(prin "^[[?9h") # Mouse reporting on
(and
(= "^[" (key))
(key 200)
(key 200)
(key)
(cons
(- (char (key)) 32)
(- (char (key)) 32) ) )
(prin "^[[?9l") ) ) # Mouse reporting off

View file

@ -0,0 +1,19 @@
import Tkinter as tk
def showxy(event):
xm, ym = event.x, event.y
str1 = "mouse at x=%d y=%d" % (xm, ym)
# show cordinates in title
root.title(str1)
# switch color to red if mouse enters a set location range
x,y, delta = 100, 100, 10
frame.config(bg='red'
if abs(xm - x) < delta and abs(ym - y) < delta
else 'yellow')
root = tk.Tk()
frame = tk.Frame(root, bg= 'yellow', width=300, height=200)
frame.bind("<Motion>", showxy)
frame.pack()
root.mainloop()

View file

@ -0,0 +1,13 @@
#simple way of ,get cursor xy data
#niwantha33@gmail.com
from Tkinter import *
win=Tk()
win.geometry("200x300")
def xy(event):
xm, ym = event.x, event.y
xy_data = "x=%d y=%d" % (xm, ym)
lab=Label(win,text=xy_data)
lab.grid(row=0,column=0)
win.bind("<Motion>",xy)
mainloop()

View file

@ -0,0 +1,4 @@
#lang racket/gui
(define-values (point _) (get-current-mouse-state))
(send point get-x)
(send point get-y)

View file

@ -0,0 +1,7 @@
Shoes.app(:title => "Mouse Position", :width => 400, :height => 400) do
@position = para "Position : ?, ?", :size => 12, :margin => 10
motion do |x, y|
@position.text = "Position : #{x}, #{y}"
end
end

View file

@ -0,0 +1,6 @@
package require Tk 8.5
set curWindow [lindex [wm stackorder .] end]
# Everything below will work with anything from Tk 8.0 onwards
set x [expr {[winfo pointerx .] - [winfo rootx $curWindow]}]
set y [expr {[winfo pointery .] - [winfo rooty $curWindow]}]
tk_messageBox -message "the mouse is at ($x,$y) in window $curWindow"