Mouse position: Difference between revisions
(19 intermediate revisions by 15 users not shown) | |||
Line 28: | Line 28: | ||
Please specify if the window may be externally created. |
Please specify if the window may be externally created. |
||
<br><br> |
<br><br> |
||
=={{header|8086 Assembly}}== |
|||
This returns the mouse's horizontal position in CX and its vertical position in DX, assuming the mouse has been enabled first. |
|||
<syntaxhighlight lang="asm">mov ax,3 |
|||
int 33h</syntaxhighlight> |
|||
=={{header|ActionScript}}== |
=={{header|ActionScript}}== |
||
This shows the mouse position in a text field at the bottom-right corner |
This shows the mouse position in a text field at the bottom-right corner |
||
and updates when the mouse is moved. |
and updates when the mouse is moved. |
||
<syntaxhighlight lang="actionscript3"> |
|||
<lang ActionScript3> |
|||
package { |
package { |
||
Line 70: | Line 75: | ||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
Line 82: | Line 87: | ||
It returns mouse coordinates relatively to a window (internally created). |
It returns mouse coordinates relatively to a window (internally created). |
||
The following program shows a button, which when pressed indicates coordinates of the mouse pointer relatively to the main window: |
The following program shows a button, which when pressed indicates coordinates of the mouse pointer relatively to the main window: |
||
< |
<syntaxhighlight lang="ada">with GLib; use GLib; |
||
with Gtk.Button; use Gtk.Button; |
with Gtk.Button; use Gtk.Button; |
||
with Gtk.Label; use Gtk.Label; |
with Gtk.Label; use Gtk.Label; |
||
Line 148: | Line 153: | ||
Gtk.Main.Main; |
Gtk.Main.Main; |
||
end Tell_Mouse;</ |
end Tell_Mouse;</syntaxhighlight> |
||
=={{header|AmigaBASIC}}== |
=={{header|AmigaBASIC}}== |
||
< |
<syntaxhighlight lang="amigabasic">MOUSE ON |
||
WHILE 1 |
WHILE 1 |
||
m=MOUSE(0) |
m=MOUSE(0) |
||
PRINT MOUSE(1),MOUSE(2) |
PRINT MOUSE(1),MOUSE(2) |
||
WEND</ |
WEND</syntaxhighlight> |
||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
System Events can report the position of the currently active window. The mouse's location is retrieved with help from AppleScriptObjC. This will be relative to the bottom-left corner of the screen. Therefore, we also retrieve the screen's height. |
System Events can report the position of the currently active window. The mouse's location is retrieved with help from AppleScriptObjC. This will be relative to the bottom-left corner of the screen. Therefore, we also retrieve the screen's height. |
||
< |
<syntaxhighlight lang="applescript">use framework "AppKit" |
||
tell application id "com.apple.SystemEvents" to tell ¬ |
tell application id "com.apple.SystemEvents" to tell ¬ |
||
Line 177: | Line 182: | ||
end tell |
end tell |
||
log coords</ |
log coords</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 184: | Line 189: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
The window may be an externally created window. |
The window may be an externally created window. |
||
< |
<syntaxhighlight lang="autohotkey">#i:: ; (Optional) Assigns a hotkey to display window info, Windows+i |
||
MouseGetPos, x, y ; Gets x/y pos relative to active window |
MouseGetPos, x, y ; Gets x/y pos relative to active window |
||
WinGetActiveTitle, WinTitle ; Gets active window title |
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 |
Traytip, Mouse position, x: %x%`ny: %y%`rWindow: %WinTitle%, 4 ; Displays the info as a Traytip for 4 seconds |
||
return</ |
return</syntaxhighlight> |
||
===with DllCall=== |
===with DllCall=== |
||
Source: [https://github.com/jNizM/AHK_DllCall_WinAPI/ GetCursorPos @github] by jNizM |
Source: [https://github.com/jNizM/AHK_DllCall_WinAPI/ GetCursorPos @github] by jNizM |
||
< |
<syntaxhighlight lang="autohotkey">GetCursorPos() |
||
{ |
{ |
||
static POINT, init := VarSetCapacity(POINT, 8, 0) && NumPut(8, POINT, "Int") |
static POINT, init := VarSetCapacity(POINT, 8, 0) && NumPut(8, POINT, "Int") |
||
Line 205: | Line 210: | ||
. "POINT structure`n`n" |
. "POINT structure`n`n" |
||
. "x-coordinate:`t`t" GetCursorPos[0] "`n" |
. "x-coordinate:`t`t" GetCursorPos[0] "`n" |
||
. "y-coordinate:`t`t" GetCursorPos[1]</ |
. "y-coordinate:`t`t" GetCursorPos[1]</syntaxhighlight> |
||
Source: [https://github.com/jNizM/AHK_DllCall_WinAPI/ GetPhysicalCursorPos @github] by jNizM |
Source: [https://github.com/jNizM/AHK_DllCall_WinAPI/ GetPhysicalCursorPos @github] by jNizM |
||
< |
<syntaxhighlight lang="autohotkey">GetPhysicalCursorPos() |
||
{ |
{ |
||
static POINT, init := VarSetCapacity(POINT, 8, 0) && NumPut(8, POINT, "Int") |
static POINT, init := VarSetCapacity(POINT, 8, 0) && NumPut(8, POINT, "Int") |
||
Line 220: | Line 225: | ||
. "POINT structure`n`n" |
. "POINT structure`n`n" |
||
. "x-coordinate:`t`t" GetPhysicalCursorPos[0] "`n" |
. "x-coordinate:`t`t" GetPhysicalCursorPos[0] "`n" |
||
. "y-coordinate:`t`t" GetPhysicalCursorPos[1]</ |
. "y-coordinate:`t`t" GetPhysicalCursorPos[1]</syntaxhighlight> |
||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
The mouse coordinates are relative to the bottom-left corner |
The mouse coordinates are relative to the bottom-left corner |
||
of the BBC BASIC main output window: |
of the BBC BASIC main output window: |
||
< |
<syntaxhighlight lang="bbcbasic"> MOUSE xmouse%, ymouse%, buttons% |
||
PRINT xmouse%, ymouse%</ |
PRINT xmouse%, ymouse%</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
{{libheader|Xlib}} |
{{libheader|Xlib}} |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#include <X11/Xlib.h> |
#include <X11/Xlib.h> |
||
Line 266: | Line 271: | ||
(void)XCloseDisplay(d); /* and close the display */ |
(void)XCloseDisplay(d); /* and close the display */ |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C++}}== |
|||
Mouse pointers are part of the window manager system, and are therefore highly platform dependent. |
|||
This example works under a Windows operating system. |
|||
<syntaxhighlight lang="c++"> |
|||
#include <iostream> |
|||
#include <windows.h> |
|||
int main() { |
|||
POINT MousePoint; |
|||
if ( GetCursorPos(&MousePoint) ) { |
|||
std::cout << MousePoint.x << ", " << MousePoint.y << std::endl; |
|||
} |
|||
} |
|||
</syntaxhighlight> |
|||
{{ out }} |
|||
<pre> |
|||
726, 506 |
|||
</pre> |
|||
=={{header|c_sharp|C#}}== |
=={{header|c_sharp|C#}}== |
||
Writes the absolute Mouse Position of the Screen into the Console |
Writes the absolute Mouse Position of the Screen into the Console |
||
< |
<syntaxhighlight lang="csharp"> |
||
using System; |
using System; |
||
using System.Windows.Forms; |
using System.Windows.Forms; |
||
Line 282: | Line 308: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
< |
<syntaxhighlight lang="lisp">(let [point (.. java.awt.MouseInfo getPointerInfo getLocation)] [(.getX point) (.getY point)])</syntaxhighlight> |
||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
Line 291: | Line 317: | ||
With the ltk library. |
With the ltk library. |
||
< |
<syntaxhighlight lang="lisp"> |
||
(ql:quickload "ltk") |
(ql:quickload "ltk") |
||
(in-package :ltk-user) |
(in-package :ltk-user) |
||
Line 300: | Line 326: | ||
;; create a small window. Enter the mouse to see lots of events. |
;; create a small window. Enter the mouse to see lots of events. |
||
(bind *tk* "<Motion>" #'motion)) |
(bind *tk* "<Motion>" #'motion)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
This prints a lot of events of the form |
This prints a lot of events of the form |
||
Line 320: | Line 346: | ||
Shows mouse-position on a label on the form. |
Shows mouse-position on a label on the form. |
||
< |
<syntaxhighlight lang="delphi">procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, |
||
Y: Integer); |
Y: Integer); |
||
begin |
begin |
||
lblMousePosition.Caption := ('X:' + IntToStr(X) + ', Y:' + IntToStr(Y)); |
lblMousePosition.Caption := ('X:' + IntToStr(X) + ', Y:' + IntToStr(Y)); |
||
end;</ |
end;</syntaxhighlight> |
||
Line 332: | Line 358: | ||
with the help of Windows and classes units. |
with the help of Windows and classes units. |
||
< |
<syntaxhighlight lang="delphi">program Project1; |
||
{$APPTYPE CONSOLE} |
{$APPTYPE CONSOLE} |
||
uses |
uses |
||
Line 346: | Line 372: | ||
sleep(300); |
sleep(300); |
||
end |
end |
||
end.</ |
end.</syntaxhighlight> |
||
=={{header|EasyLang}}== |
=={{header|EasyLang}}== |
||
[https://easylang.dev/show/#cod=y80vS1UwNFCwMODKz1PIzS8tTo3PBYpxKSgoJOekJhaBGClFieXpRZkpIHZJakUJVF2FgpqCEhCqQfmVXHpcXAA= Run it] |
|||
[https://easylang.online/ide/?run=on%20mouse_move%0A%20%20clear_screen%0A%20%20draw_text%20mouse_x%20%26%20%22%20%22%20%26%20mouse_y%0A.%0A Run it] |
|||
<syntaxhighlight> |
|||
<lang>on mouse_move |
|||
move 10 80 |
|||
clear_screen |
|||
on mouse_move |
|||
draw_text mouse_x & " " & mouse_y |
|||
clear |
|||
.</lang> |
|||
drawgrid |
|||
text mouse_x & " " & mouse_y |
|||
. |
|||
</syntaxhighlight> |
|||
=={{header|EchoLisp}}== |
=={{header|EchoLisp}}== |
||
When the '''plot''' library is loaded, the mouse position - relative to the plotting area coordinates, is displayed inside the info panel. |
When the '''plot''' library is loaded, the mouse position - relative to the plotting area coordinates, is displayed inside the info panel. |
||
< |
<syntaxhighlight lang="lisp"> |
||
(lib 'plot) |
(lib 'plot) |
||
(plot-x-minmax 10) ; set logical dimensions of plotting area |
(plot-x-minmax 10) ; set logical dimensions of plotting area |
||
Line 367: | Line 397: | ||
;; the mouse position is displayed as , for example, [ x: 5.6 y : 88.7] |
;; the mouse position is displayed as , for example, [ x: 5.6 y : 88.7] |
||
;; 0 <= x <= 10, 0 <= y <= 100 |
;; 0 <= x <= 10, 0 <= y <= 100 |
||
</syntaxhighlight> |
|||
</lang> |
|||
--[[User:Neo.abhinav|Neo.abhinav]] 17:00, 6 May 2011 (UTC) |
--[[User:Neo.abhinav|Neo.abhinav]] 17:00, 6 May 2011 (UTC) |
||
=={{header|Elm}}== |
=={{header|Elm}}== |
||
< |
<syntaxhighlight lang="elm">import Graphics.Element exposing (Element, show) |
||
import Mouse |
import Mouse |
||
Line 378: | Line 408: | ||
main : Signal Element |
main : Signal Element |
||
main = |
main = |
||
Signal.map show Mouse.position</ |
Signal.map show Mouse.position</syntaxhighlight> |
||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |
||
Line 384: | Line 414: | ||
the frame the mouse is over and where the mouse is within that frame can be obtained with |
the frame the mouse is over and where the mouse is within that frame can be obtained with |
||
< |
<syntaxhighlight lang="lisp">(mouse-pixel-position) |
||
;; => (FRAME . (X . Y))</syntaxhighlight> |
|||
=> |
|||
(FRAME . (X . Y))</lang> |
|||
Or <code>mouse-position</code> for characters instead of pixels. |
Or <code>mouse-position</code> for characters instead of pixels. |
||
Line 396: | Line 425: | ||
=={{header|ERRE}}== |
=={{header|ERRE}}== |
||
This example program, taken from distribution disk, shows the mouse position in a text field at the bottom-right corner and updates when the mouse is moved. |
This example program, taken from distribution disk, shows the mouse position in a text field at the bottom-right corner and updates when the mouse is moved. |
||
<syntaxhighlight lang="erre"> |
|||
<lang ERRE> |
|||
! |
! |
||
! MOUSE WITH 'MOUSE.LIB' LIBRARY |
! MOUSE WITH 'MOUSE.LIB' LIBRARY |
||
Line 476: | Line 505: | ||
CLS |
CLS |
||
END PROGRAM |
END PROGRAM |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
Line 483: | Line 512: | ||
If the question was for the point relative to the current window, |
If the question was for the point relative to the current window, |
||
life would be much simpler. |
life would be much simpler. |
||
< |
<syntaxhighlight lang="fsharp">open System.Windows.Forms |
||
open System.Runtime.InteropServices |
open System.Runtime.InteropServices |
||
Line 504: | Line 533: | ||
ScreenToClient(hwnd, &ptFs) |> ignore |
ScreenToClient(hwnd, &ptFs) |> ignore |
||
ptFs |
ptFs |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
Works only in the graphical listener. |
Works only in the graphical listener. |
||
Replaces the text in the button with the relative and absolute coordinates of the mouse |
Replaces the text in the button with the relative and absolute coordinates of the mouse |
||
< |
<syntaxhighlight lang="factor">: replace-text ( button text -- ) |
||
[ drop children>> pop drop ] [ >label add-gadget drop ] 2bi ; |
[ drop children>> pop drop ] [ >label add-gadget drop ] 2bi ; |
||
: present-locations ( loc1 loc2 -- string ) |
: present-locations ( loc1 loc2 -- string ) |
||
Line 522: | Line 551: | ||
] |
] |
||
<border-button> gadget. ; |
<border-button> gadget. ; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
Also includes the state of the mouse wheel and mouse buttons, since these are provided by the same subroutine that provides the cursor position. |
Also includes the state of the mouse wheel and mouse buttons, since these are provided by the same subroutine that provides the cursor position. |
||
< |
<syntaxhighlight lang="freebasic"> |
||
type MOUSE |
type MOUSE |
||
'mouse position, button state, wheel state |
'mouse position, button state, wheel state |
||
Line 555: | Line 584: | ||
print "Wheel scrolls: ", mouse.wheel," " |
print "Wheel scrolls: ", mouse.wheel," " |
||
end if |
end if |
||
wend</ |
wend</syntaxhighlight> |
||
=={{header|FutureBasic}}== |
|||
<syntaxhighlight lang="futurebasic"> |
|||
subclass window 1, @"Click somewhere in the window" |
|||
void local fn DoDialog( ev as long ) |
|||
select ( ev ) |
|||
case _windowMouseDown |
|||
CGPoint pt = fn EventLocationInWindow |
|||
cls : printf @"%.0fx, %.0fy",pt.x,pt.y |
|||
end select |
|||
end fn |
|||
on dialog fn DoDialog |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
=={{header|Gambas}}== |
=={{header|Gambas}}== |
||
Line 564: | Line 612: | ||
this is the only widget that can track pointer movement within gambas. |
this is the only widget that can track pointer movement within gambas. |
||
< |
<syntaxhighlight lang="gambas"> |
||
PUBLIC SUB Form1_MouseMove() |
PUBLIC SUB Form1_MouseMove() |
||
PRINT mouse.X |
PRINT mouse.X |
||
PRINT Mouse.Y |
PRINT Mouse.Y |
||
END |
END |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
Line 575: | Line 623: | ||
<br> |
<br> |
||
The active window may be externally created. |
The active window may be externally created. |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 609: | Line 657: | ||
fmt.Println("Problem when finding PID(s) of", name) |
fmt.Println("Problem when finding PID(s) of", name) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 629: | Line 677: | ||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
Based on Java solution: |
Based on Java solution: |
||
< |
<syntaxhighlight lang="groovy">1.upto(5) { |
||
Thread.sleep(1000) |
Thread.sleep(1000) |
||
def p = java.awt.MouseInfo.pointerInfo.location |
def p = java.awt.MouseInfo.pointerInfo.location |
||
println "${it}: x=${p.@x} y=${p.@y}" |
println "${it}: x=${p.@x} y=${p.@y}" |
||
}</ |
}</syntaxhighlight> |
||
Sample output: |
Sample output: |
||
Line 645: | Line 693: | ||
Mouse click positions for windows created internally. |
Mouse click positions for windows created internally. |
||
X and Y are in units of current xy axes (optional: invisible). |
X and Y are in units of current xy axes (optional: invisible). |
||
< |
<syntaxhighlight lang="hicest"> WINDOW(WINdowhandle=handle) |
||
AXIS(WINdowhandle=handle, MouSeCall=Mouse_Callback, MouSeX=X, MouSeY=Y) |
AXIS(WINdowhandle=handle, MouSeCall=Mouse_Callback, MouSeX=X, MouSeY=Y) |
||
END |
END |
||
Line 651: | Line 699: | ||
SUBROUTINE Mouse_Callback() |
SUBROUTINE Mouse_Callback() |
||
WRITE(Messagebox, Name) X, Y |
WRITE(Messagebox, Name) X, Y |
||
END</ |
END</syntaxhighlight> |
||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
In Icon/Unicon the mouse position may be tracked between button presses for any window created by the program. |
In Icon/Unicon the mouse position may be tracked between button presses for any window created by the program. |
||
The following code snippet taken from the Icon Graphics Book on page 197-198 shows how to track the mouse. |
The following code snippet taken from the Icon Graphics Book on page 197-198 shows how to track the mouse. |
||
< |
<syntaxhighlight lang="icon">until *Pending() > 0 & Event() == "q" do { # loop until there is something to do |
||
px := WAttrib("pointerx") |
px := WAttrib("pointerx") |
||
py := WAttrib("pointery") |
py := WAttrib("pointery") |
||
Line 662: | Line 710: | ||
WDelay(5) # wait and share processor |
WDelay(5) # wait and share processor |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{works with|Java|1.5+}} |
{{works with|Java|1.5+}} |
||
The mouse position can be checked at any time by calling |
The mouse position can be checked at any time by calling |
||
< |
<syntaxhighlight lang="java5">Point mouseLocation = MouseInfo.getPointerInfo().getLocation();</syntaxhighlight> |
||
This returns a point on the entire screen, rather than relative to a particular window. This call can be combined with <code>getLocation()</code> from any <code>Component</code> (including a <code>Frame</code>, which is a window) to get the location relative to that <code>Component</code>. |
This returns a point on the entire screen, rather than relative to a particular window. This call can be combined with <code>getLocation()</code> from any <code>Component</code> (including a <code>Frame</code>, which is a window) to get the location relative to that <code>Component</code>. |
||
Line 677: | Line 725: | ||
One of many ways to add an event listener: |
One of many ways to add an event listener: |
||
< |
<syntaxhighlight lang="javascript">document.addEventListener('mousemove', function(e){ |
||
var position = { x: e.clientX, y: e.clientY } |
var position = { x: e.clientX, y: e.clientY } |
||
}</ |
}</syntaxhighlight> |
||
In the above example, the window may not be external. |
In the above example, the window may not be external. |
||
Line 685: | Line 733: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">using Gtk |
||
const win = GtkWindow("Get Mouse Position", 600, 800) |
const win = GtkWindow("Get Mouse Position", 600, 800) |
||
Line 700: | Line 748: | ||
signal_connect(endit, win, :destroy) |
signal_connect(endit, win, :destroy) |
||
wait(c) |
wait(c) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Groovy}} |
{{trans|Groovy}} |
||
< |
<syntaxhighlight lang="scala">// version 1.1.2 |
||
import java.awt.MouseInfo |
import java.awt.MouseInfo |
||
Line 714: | Line 762: | ||
println("${it}: x = ${"%-4d".format(p.x)} y = ${"%-4d".format(p.y)}") |
println("${it}: x = ${"%-4d".format(p.x)} y = ${"%-4d".format(p.y)}") |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
Sample output: |
Sample output: |
||
{{out}} |
{{out}} |
||
Line 728: | Line 776: | ||
This example gets the mouse position based on the active window. |
This example gets the mouse position based on the active window. |
||
Click on other windows to get relative mouse position based on those windows. |
Click on other windows to get relative mouse position based on those windows. |
||
< |
<syntaxhighlight lang="lb"> nomainwin |
||
UpperLeftX = DisplayWidth-WindowWidth |
UpperLeftX = DisplayWidth-WindowWidth |
||
Line 765: | Line 813: | ||
y = point.y.struct |
y = point.y.struct |
||
CursorPos$=x; ",";y |
CursorPos$=x; ",";y |
||
end function</ |
end function</syntaxhighlight> |
||
=={{header|Lingo}}== |
=={{header|Lingo}}== |
||
< |
<syntaxhighlight lang="lingo">put _mouse.mouseLoc |
||
-- point(310, 199)</ |
-- point(310, 199)</syntaxhighlight> |
||
=={{header| |
=={{header|xTalk}}== |
||
{{works with|HyperCard}} {{works with|LiveCode}} |
|||
<lang liveCode> |
|||
<syntaxhighlight lang="livecode"> |
|||
-- Method 1: |
-- Method 1: |
||
-- this script in either the stack script or the card script to get position relative to the current stack window |
-- this script in either the stack script or the card script to get position relative to the current stack window |
||
Line 798: | Line 847: | ||
148,521 -- relative to current screen |
148,521 -- relative to current screen |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|LiveCode Builder}}== |
=={{header|LiveCode Builder}}== |
||
<syntaxhighlight lang="livecode builder"> |
|||
<lang LiveCode Builder> |
|||
LiveCode Builder (LCB) is a slightly lower level, strictly typed variant of LiveCode Script (LCS) used for making add-on extensions to LiveCode Script |
LiveCode Builder (LCB) is a slightly lower level, strictly typed variant of LiveCode Script (LCS) used for making add-on extensions to LiveCode Script |
||
Line 813: | Line 863: | ||
log "mouse position is within the widget bounds" |
log "mouse position is within the widget bounds" |
||
end if |
end if |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Logo}}== |
=={{header|Logo}}== |
||
< |
<syntaxhighlight lang="logo">show mousepos ; [-250 250]</syntaxhighlight> |
||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
<syntaxhighlight lang="m2000 interpreter"> |
|||
<lang M2000 Interpreter> |
|||
Module Checkit { |
Module Checkit { |
||
\\ works when console is the active window |
\\ works when console is the active window |
||
Line 852: | Line 902: | ||
} |
} |
||
CheckIt |
CheckIt |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Mathematica}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">MousePosition["WindowAbsolute"]</syntaxhighlight> |
||
=={{header|MATLAB}}== |
=={{header|MATLAB}}== |
||
<lang |
<syntaxhighlight lang="matlab">get(0,'PointerLocation')</syntaxhighlight> |
||
=={{header|MAXScript}}== |
=={{header|MAXScript}}== |
||
Creates a window on the screen and shows mouse position as it moves. |
Creates a window on the screen and shows mouse position as it moves. |
||
<syntaxhighlight lang="maxscript"> |
|||
<lang MAXScript> |
|||
try destroydialog mousePos catch () |
try destroydialog mousePos catch () |
||
Line 884: | Line 934: | ||
createdialog mousepos |
createdialog mousepos |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|MiniScript}}== |
=={{header|MiniScript}}== |
||
{{works with|Mini Micro}} |
{{works with|Mini Micro}} |
||
<lang |
<syntaxhighlight lang="miniscript">print mouse.x, mouse.y</syntaxhighlight> |
||
=={{header|Nanoquery}}== |
=={{header|Nanoquery}}== |
||
< |
<syntaxhighlight lang="nanoquery">import Nanoquery.Util.Windows |
||
// a function to handle the mouse moved event |
// a function to handle the mouse moved event |
||
Line 902: | Line 952: | ||
w.setSize(500, 500) |
w.setSize(500, 500) |
||
w.setHandler(w.mouseMoved, mouse_moved) |
w.setHandler(w.mouseMoved, mouse_moved) |
||
w.show()</ |
w.show()</syntaxhighlight> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{libheader|gintro}} |
{{libheader|gintro}} |
||
< |
<syntaxhighlight lang="nim">import gintro/[glib, gobject, gtk, gio] |
||
import gintro/gdk except Window |
import gintro/gdk except Window |
||
Line 932: | Line 982: | ||
let app = newApplication(Application, "Rosetta.MousePosition") |
let app = newApplication(Application, "Rosetta.MousePosition") |
||
discard app.connect("activate", activate) |
discard app.connect("activate", activate) |
||
discard app.run()</ |
discard app.run()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 949: | Line 999: | ||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
equivalent to the C example, uses the Xlib binding [http:// |
equivalent to the C example, uses the Xlib binding [http://decapode314.free.fr/ocaml/Xlib/ ocaml-xlib] |
||
< |
<syntaxhighlight lang="ocaml">open Xlib |
||
let () = |
let () = |
||
Line 973: | Line 1,023: | ||
xCloseDisplay d; |
xCloseDisplay d; |
||
;;</ |
;;</syntaxhighlight> |
||
=={{header|Octave}}== |
=={{header|Octave}}== |
||
To get the X,Y coordinates of N mouse clicks in the current figure, |
To get the X,Y coordinates of N mouse clicks in the current figure, |
||
one can use this: |
one can use this: |
||
< |
<syntaxhighlight lang="octave">[X, Y, BUTTONS] = ginput(N);</syntaxhighlight> |
||
Example: |
Example: |
||
<pre>>> [X, Y, BUTTONS] = ginput(4) |
<pre>>> [X, Y, BUTTONS] = ginput(4) |
||
Line 1,002: | Line 1,052: | ||
2 |
2 |
||
</pre> |
</pre> |
||
=={{header|Odin}}== |
|||
<syntaxhighlight lang="odin">package main |
|||
import "core:fmt" |
|||
import "vendor:sdl2" |
|||
main :: proc() { |
|||
using sdl2 |
|||
window: ^Window = --- |
|||
renderer: ^Renderer = --- |
|||
event: Event = --- |
|||
Init(INIT_VIDEO) |
|||
CreateWindowAndRenderer( |
|||
640, 480, |
|||
WINDOW_SHOWN, |
|||
&window, &renderer |
|||
) |
|||
SetWindowTitle(window, "Empty window") |
|||
RenderPresent(renderer) |
|||
for event.type != .QUIT { |
|||
if event.type == .MOUSEMOTION { |
|||
using event.motion |
|||
fmt.printf("x=%d y=%d\n", x, y) |
|||
} |
|||
Delay(10) |
|||
PollEvent(&event) |
|||
} |
|||
DestroyRenderer(renderer) |
|||
DestroyWindow(window) |
|||
Quit() |
|||
}</syntaxhighlight> |
|||
=={{header|Oz}}== |
=={{header|Oz}}== |
||
Repeatedly shows the mouse coordinates relative to the foremost window of the application. |
Repeatedly shows the mouse coordinates relative to the foremost window of the application. |
||
< |
<syntaxhighlight lang="oz">declare |
||
[QTk] = {Module.link ['x-oz://system/wp/QTk.ozf']} |
[QTk] = {Module.link ['x-oz://system/wp/QTk.ozf']} |
||
WindowClosed = {NewCell false} |
WindowClosed = {NewCell false} |
||
Line 1,025: | Line 1,113: | ||
#", y: "#(Winfo.pointery - Winfo.rooty))} |
#", y: "#(Winfo.pointery - Winfo.rooty))} |
||
{Delay 250} |
{Delay 250} |
||
end</ |
end</syntaxhighlight> |
||
=={{header|Pebble}}== |
|||
<syntaxhighlight lang="pebble">;mouse demonstration |
|||
;compile with Pebble |
|||
;for textmode x86 DOS |
|||
;requires mouse driver |
|||
program examples\mouse |
|||
use mouse.inc |
|||
data |
|||
int mousex[0] |
|||
int mousey[0] |
|||
int mouseb[0] |
|||
int speed[0] |
|||
int i[0] |
|||
begin |
|||
echo "Enter 1-200 for slow/DOS/emulated machines." |
|||
echo "Enter 500-20000 for faster/Windows machines." |
|||
input [speed] |
|||
cls |
|||
call showmouse |
|||
label mainloop |
|||
;clear mouse coordinates |
|||
cursor 0, 0 |
|||
echo " " |
|||
echo " " |
|||
;get and display mouse coordinates |
|||
call readmouse |
|||
cursor 0, 0 |
|||
echo [mousey] |
|||
crlf |
|||
echo [mousex] |
|||
;display exit button |
|||
cursor 76, 0 |
|||
echo "[X]" |
|||
;check if exit button has been clicked |
|||
if [mouseb] = 1 & [mousex] >= 76 & [mousex] <= 79 & [mousey] = 0 then |
|||
kill |
|||
endif |
|||
;loop 100 times since some machines do not support the WAIT command |
|||
[i] = 0 |
|||
label delay |
|||
+1 [i] |
|||
wait 1 |
|||
if [i] < [speed] then delay |
|||
goto mainloop |
|||
end</syntaxhighlight> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
Line 1,032: | Line 1,193: | ||
When you move the mouse over the created window, |
When you move the mouse over the created window, |
||
the mouse position get printed and the program terminates. |
the mouse position get printed and the program terminates. |
||
< |
<syntaxhighlight lang="perl">use SDL; |
||
use SDL::Events; |
use SDL::Events; |
||
use SDLx::App; |
use SDLx::App; |
||
Line 1,045: | Line 1,206: | ||
} ); |
} ); |
||
$app->run; |
$app->run; |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>x=15 y=304</pre> |
<pre>x=15 y=304</pre> |
||
Line 1,056: | Line 1,217: | ||
Note that canvasmotion coordinates are relative to the top left of the canvas, whereas the other two are absolute. |
Note that canvasmotion coordinates are relative to the top left of the canvas, whereas the other two are absolute. |
||
{{libheader|Phix/pGUI}} |
{{libheader|Phix/pGUI}} |
||
< |
<syntaxhighlight lang="phix">-- demo\rosetta\Mouse_position.exw |
||
include pGUI.e |
include pGUI.e |
||
Line 1,114: | Line 1,275: | ||
IupClose() |
IupClose() |
||
end procedure |
end procedure |
||
main()</ |
main()</syntaxhighlight> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
Line 1,122: | Line 1,283: | ||
The returned value is (X . Y), where X is the |
The returned value is (X . Y), where X is the |
||
column and Y the line number. |
column and Y the line number. |
||
< |
<syntaxhighlight lang="picolisp">(de mousePosition () |
||
(prog2 |
(prog2 |
||
(prin "^[[?9h") # Mouse reporting on |
(prin "^[[?9h") # Mouse reporting on |
||
Line 1,133: | Line 1,294: | ||
(- (char (key)) 32) |
(- (char (key)) 32) |
||
(- (char (key)) 32) ) ) |
(- (char (key)) 32) ) ) |
||
(prin "^[[?9l") ) ) # Mouse reporting off</ |
(prin "^[[?9l") ) ) # Mouse reporting off</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>: (mousePosition) |
<pre>: (mousePosition) |
||
Line 1,140: | Line 1,301: | ||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
The mouse position can be obtained by these two commands: |
The mouse position can be obtained by these two commands: |
||
< |
<syntaxhighlight lang="purebasic">x = WindowMouseX(#MyWindow) |
||
y = WindowMouseY(#MyWindow)</ |
y = WindowMouseY(#MyWindow)</syntaxhighlight> |
||
This example repeatedly shows the mouse coordinates |
This example repeatedly shows the mouse coordinates |
||
relative to the window created in the application. |
relative to the window created in the application. |
||
< |
<syntaxhighlight lang="purebasic">#MyWindow = 0 |
||
#Label_txt = 0 |
#Label_txt = 0 |
||
#MousePos_txt = 1 |
#MousePos_txt = 1 |
||
Line 1,163: | Line 1,324: | ||
SetGadgetText(#MousePos_txt,"(" + Str(x) + "," + Str(y) + ")") |
SetGadgetText(#MousePos_txt,"(" + Str(x) + "," + Str(y) + ")") |
||
ForEver |
ForEver |
||
EndIf</ |
EndIf</syntaxhighlight> |
||
=={{header|Processing}}== |
=={{header|Processing}}== |
||
< |
<syntaxhighlight lang="java">void setup(){ |
||
size(640, 480); |
size(640, 480); |
||
} |
} |
||
Line 1,174: | Line 1,335: | ||
ellipse(mouseX, mouseY, 5, 5); // graphic output example |
ellipse(mouseX, mouseY, 5, 5); // graphic output example |
||
println("x:" + mouseX + " y:" + mouseY); |
println("x:" + mouseX + " y:" + mouseY); |
||
}</ |
}</syntaxhighlight> |
||
==={{header|Processing Python mode}}=== |
==={{header|Processing Python mode}}=== |
||
< |
<syntaxhighlight lang="python">def setup(): |
||
size(640, 480) |
size(640, 480) |
||
Line 1,183: | Line 1,344: | ||
# mouseX and mouseY provide the current mouse position |
# mouseX and mouseY provide the current mouse position |
||
ellipse(mouseX, mouseY, 5, 5) # graphic output example |
ellipse(mouseX, mouseY, 5, 5) # graphic output example |
||
println("x:{} y:{}".format(mouseX, mouseY))</ |
println("x:{} y:{}".format(mouseX, mouseY))</syntaxhighlight> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Line 1,195: | Line 1,356: | ||
Code is based on post in Daniweb: http://www.daniweb.com/forums/post616327.html#post616327 by ZZucker |
Code is based on post in Daniweb: http://www.daniweb.com/forums/post616327.html#post616327 by ZZucker |
||
< |
<syntaxhighlight lang="python"> |
||
import Tkinter as tk |
import Tkinter as tk |
||
Line 1,215: | Line 1,376: | ||
root.mainloop() |
root.mainloop() |
||
</syntaxhighlight> |
|||
</lang> |
|||
---------------- |
---------------- |
||
< |
<syntaxhighlight lang="python"> |
||
#simple way of ,get cursor xy data |
#simple way of ,get cursor xy data |
||
Line 1,231: | Line 1,392: | ||
win.bind("<Motion>",xy) |
win.bind("<Motion>",xy) |
||
mainloop() |
mainloop() |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
Line 1,237: | Line 1,398: | ||
The mouse position can be queried at any time with a function in a GUI context. |
The mouse position can be queried at any time with a function in a GUI context. |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang racket/gui |
#lang racket/gui |
||
(define-values [point _] (get-current-mouse-state)) |
(define-values [point _] (get-current-mouse-state)) |
||
(send point get-x) |
(send point get-x) |
||
(send point get-y) |
(send point get-y) |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
{{works with|rakudo/jvm|2013-12-03}} |
{{works with|rakudo/jvm|2013-12-03}} |
||
<lang |
<syntaxhighlight lang="raku" line>use java::awt::MouseInfo:from<java>; |
||
given MouseInfo.getPointerInfo.getLocation { |
given MouseInfo.getPointerInfo.getLocation { |
||
say .getX, 'x', .getY; |
say .getX, 'x', .getY; |
||
}</ |
}</syntaxhighlight> |
||
An implementation that will work on any X11 windowing system. Reports mouse position, window ID# and window name for whichever window the mouse pointer is over. Automatically moves mouse for hands-off testing purposes. |
An implementation that will work on any X11 windowing system. Reports mouse position, window ID# and window name for whichever window the mouse pointer is over. Automatically moves mouse for hands-off testing purposes. |
||
{{works with|Rakudo|2018.11}} |
{{works with|Rakudo|2018.11}} |
||
<lang |
<syntaxhighlight lang="raku" line>use X11::libxdo; |
||
my $xdo = Xdo.new; |
my $xdo = Xdo.new; |
||
Line 1,277: | Line 1,438: | ||
} |
} |
||
say '';</ |
say '';</syntaxhighlight> |
||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
Line 1,284: | Line 1,445: | ||
The movement procedure uses the mouse position information |
The movement procedure uses the mouse position information |
||
<syntaxhighlight lang="ring"> |
|||
<lang Ring> |
|||
Load "guilib.ring" |
Load "guilib.ring" |
||
Line 1,347: | Line 1,508: | ||
} |
} |
||
ok |
ok |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
Line 1,353: | Line 1,514: | ||
{{libheader|Shoes}} |
{{libheader|Shoes}} |
||
< |
<syntaxhighlight lang="ruby">Shoes.app(:title => "Mouse Position", :width => 400, :height => 400) do |
||
@position = para "Position : ?, ?", :size => 12, :margin => 10 |
@position = para "Position : ?, ?", :size => 12, :margin => 10 |
||
Line 1,359: | Line 1,520: | ||
@position.text = "Position : #{x}, #{y}" |
@position.text = "Position : #{x}, #{y}" |
||
end |
end |
||
end</ |
end</syntaxhighlight> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
Prints current location of the mouse cursor relative to any active window. |
Prints current location of the mouse cursor relative to any active window. |
||
This example relies on the Windows API. |
This example relies on the Windows API. |
||
< |
<syntaxhighlight lang="rust">// rustc 0.9 (7613b15 2014-01-08 18:04:43 -0800) |
||
use std::libc::{BOOL, HANDLE, LONG}; |
use std::libc::{BOOL, HANDLE, LONG}; |
||
Line 1,400: | Line 1,561: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>x: 550, y: 614 |
<pre>x: 550, y: 614 |
||
Line 1,412: | Line 1,573: | ||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
{{libheader|Scala}}< |
{{libheader|Scala}}<syntaxhighlight lang="scala">import java.awt.MouseInfo |
||
object MousePosition extends App { |
object MousePosition extends App { |
||
val mouseLocation = MouseInfo.getPointerInfo.getLocation |
val mouseLocation = MouseInfo.getPointerInfo.getLocation |
||
println (mouseLocation) |
println (mouseLocation) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
Line 1,422: | Line 1,583: | ||
and [http://seed7.sourceforge.net/libraries/graph.htm#pointerYPos%28in_PRIMITIVE_WINDOW%29 pointerYPos] from the |
and [http://seed7.sourceforge.net/libraries/graph.htm#pointerYPos%28in_PRIMITIVE_WINDOW%29 pointerYPos] from the |
||
[http://seed7.sourceforge.net/libraries/graph.htm graph.s7i] library determine the actual X and Y position of the mouse pointer, relative to the given window: |
[http://seed7.sourceforge.net/libraries/graph.htm graph.s7i] library determine the actual X and Y position of the mouse pointer, relative to the given window: |
||
< |
<syntaxhighlight lang="seed7">xPos := pointerXPos(curr_win); |
||
yPos := pointerYPos(curr_win);</ |
yPos := pointerYPos(curr_win);</syntaxhighlight> |
||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |
||
Sending the message <tt>position</tt> to the <tt>activeHand</tt> of the <tt>World</tt> returns a <tt>Point</tt> object: |
Sending the message <tt>position</tt> to the <tt>activeHand</tt> of the <tt>World</tt> returns a <tt>Point</tt> object: |
||
< |
<syntaxhighlight lang="smalltalk"> |
||
World activeHand position. " (394@649.0)" |
World activeHand position. " (394@649.0)" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Standard ML}}== |
=={{header|Standard ML}}== |
||
Works with PolyML |
Works with PolyML |
||
< |
<syntaxhighlight lang="standard ml">open XWindows ; |
||
val dp = XOpenDisplay "" ; |
val dp = XOpenDisplay "" ; |
||
val w = XCreateSimpleWindow (RootWindow dp) origin (Area {x=0,y=0,w=400,h=300}) 3 0 0xffffff ; |
val w = XCreateSimpleWindow (RootWindow dp) origin (Area {x=0,y=0,w=400,h=300}) 3 0 0xffffff ; |
||
Line 1,442: | Line 1,603: | ||
) ; |
) ; |
||
XQueryPointer focus ; |
XQueryPointer focus ; |
||
XQueryPointer w;</ |
XQueryPointer w;</syntaxhighlight> |
||
result: position wrt root window and active window, resp wrt root window and window w |
result: position wrt root window and active window, resp wrt root window and window w |
||
val it = |
val it = |
||
Line 1,455: | Line 1,616: | ||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
{{libheader|Tk}} |
{{libheader|Tk}} |
||
< |
<syntaxhighlight lang="tcl">package require Tk 8.5 |
||
set curWindow [lindex [wm stackorder .] end] |
set curWindow [lindex [wm stackorder .] end] |
||
# Everything below will work with anything from Tk 8.0 onwards |
# Everything below will work with anything from Tk 8.0 onwards |
||
set x [expr {[winfo pointerx .] - [winfo rootx $curWindow]}] |
set x [expr {[winfo pointerx .] - [winfo rootx $curWindow]}] |
||
set y [expr {[winfo pointery .] - [winfo rooty $curWindow]}] |
set y [expr {[winfo pointery .] - [winfo rooty $curWindow]}] |
||
tk_messageBox -message "the mouse is at ($x,$y) in window $curWindow"</ |
tk_messageBox -message "the mouse is at ($x,$y) in window $curWindow"</syntaxhighlight> |
||
screen coordinates |
screen coordinates |
||
<syntaxhighlight lang="tcl">package require Tk |
|||
<lang tcl>puts "monitor/display coordinate x = [winfo pointerx .]"</lang> |
|||
puts "monitor/display coordinate x = [winfo pointerx .]"</syntaxhighlight> |
|||
=={{header|Uxntal}}== |
|||
<syntaxhighlight lang="Uxntal">|00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1 |
|||
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1 |
|||
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |
|||
|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &pad $3 &scrollx $2 &scrolly $2 |
|||
|0100 |
|||
;on-mouse .Mouse/vector DEO2 |
|||
BRK |
|||
@on-mouse |
|||
.Mouse/x DEI2 print-hex2 |
|||
#20 .Console/write DEO |
|||
.Mouse/y DEI2 print-hex2 |
|||
#0a .Console/write DEO |
|||
BRK |
|||
@print-hex |
|||
DUP #04 SFT print-digit #0f AND print-digit |
|||
JMP2r |
|||
@print-hex2 |
|||
SWP print-hex print-hex |
|||
JMP2r |
|||
@print-digit |
|||
DUP #09 GTH #27 MUL ADD #30 ADD .Console/write DEO |
|||
JMP2r</syntaxhighlight> |
|||
=={{header|Vala}}== |
|||
<syntaxhighlight lang="vala">// GTK 4 |
|||
public class Example : Gtk.Application { |
|||
public Example() { |
|||
Object(application_id: "my.application", |
|||
flags: ApplicationFlags.FLAGS_NONE); |
|||
activate.connect(() => { |
|||
var window = new Gtk.ApplicationWindow(this); |
|||
var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 20); |
|||
var button = new Gtk.Button.with_label("Get Cursor Position"); |
|||
button.clicked.connect((a) => { |
|||
double x, y; |
|||
var device_pointer= window.get_display().get_default_seat().get_pointer(); |
|||
window.get_surface().get_device_position(device_pointer, out x, out y, null); |
|||
label.set_text(x.to_string() + "," + y.to_string()); |
|||
}); |
|||
box.append(label); |
|||
box.append(button); |
|||
window.set_child(box); |
|||
window.present(); |
|||
}); |
|||
} |
|||
public static int main(string[] argv) { |
|||
return new Example().run(argv); |
|||
} |
|||
}</syntaxhighlight> |
|||
=={{header|Visual Basic}}== |
=={{header|Visual Basic}}== |
||
Line 1,473: | Line 1,692: | ||
(so if the pointer is over a button on the current form, |
(so if the pointer is over a button on the current form, |
||
the event will only fire for the button, ''not'' the form). |
the event will only fire for the button, ''not'' the form). |
||
< |
<syntaxhighlight lang="vb">Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) |
||
'X and Y are in "twips" -- 15 twips per pixel |
'X and Y are in "twips" -- 15 twips per pixel |
||
Me.Print "X:" & X |
Me.Print "X:" & X |
||
Me.Print "Y:" & Y |
Me.Print "Y:" & Y |
||
End Sub</ |
End Sub</syntaxhighlight> |
||
The second method uses the [[wp:Windows API|Windows API]], |
The second method uses the [[wp:Windows API|Windows API]], |
||
and can be easily translated to any language that can make API calls. |
and can be easily translated to any language that can make API calls. |
||
This example uses a <code>Timer</code> control to check the mouse position. |
This example uses a <code>Timer</code> control to check the mouse position. |
||
< |
<syntaxhighlight lang="vb">Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long |
||
Private Type POINTAPI |
Private Type POINTAPI |
||
Line 1,497: | Line 1,716: | ||
Me.Print "X:" & Pt.X |
Me.Print "X:" & Pt.X |
||
Me.Print "Y:" & Pt.Y |
Me.Print "Y:" & Pt.Y |
||
End Sub</ |
End Sub</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|DOME}} |
{{libheader|DOME}} |
||
< |
<syntaxhighlight lang="wren">import "dome" for Window |
||
import "graphics" for Canvas |
import "graphics" for Canvas |
||
import "input" for Mouse |
import "input" for Mouse |
||
Line 1,533: | Line 1,752: | ||
static draw(alpha) {} |
static draw(alpha) {} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,563: | Line 1,782: | ||
does not make Windows applications (however see "Simple windowed application"). |
does not make Windows applications (however see "Simple windowed application"). |
||
< |
<syntaxhighlight lang="xpl0">include c:\cxpl\stdlib; |
||
if not OpenMouse then Text(0, "A mouse is required") |
if not OpenMouse then Text(0, "A mouse is required") |
||
else [ShowMouse(true); |
else [ShowMouse(true); |
||
IntOut(0, GetMousePosition(0)); ChOut(0, ^,); |
IntOut(0, GetMousePosition(0)); ChOut(0, ^,); |
||
IntOut(0, GetMousePosition(1)); CrLf(0); |
IntOut(0, GetMousePosition(1)); CrLf(0); |
||
]</ |
]</syntaxhighlight> |
||
{{out|Example output}} |
{{out|Example output}} |
Latest revision as of 19:38, 29 March 2024
You are encouraged to solve this task according to the task description, using any language you may know.
- Task
Get the current location of the mouse cursor relative to the active window.
Please specify if the window may be externally created.
8086 Assembly
This returns the mouse's horizontal position in CX and its vertical position in DX, assuming the mouse has been enabled first.
mov ax,3
int 33h
ActionScript
This shows the mouse position in a text field at the bottom-right corner and updates when the mouse is moved.
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class MousePosition extends Sprite {
private var _textField:TextField = new TextField();
public function MousePosition() {
if ( stage ) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
_textField.autoSize = TextFieldAutoSize.RIGHT;
_textField.x = stage.stageWidth - 10;
_textField.defaultTextFormat = new TextFormat(null, 15);
_textField.text = "Mouse position: X = 0, Y = 0";
_textField.y = stage.stageHeight - _textField.textHeight - 14;
addChild(_textField);
addEventListener(Event.ENTER_FRAME, _onEnterFrame);
}
private function _onEnterFrame(e:Event):void {
_textField.text = "Mouse position: X = " + stage.mouseX + ", Y = " + stage.mouseY;
}
}
}
Ada
The GTK procedure is Get_Pointer. It returns mouse coordinates relatively to a window (internally created). The following program shows a button, which when pressed indicates coordinates of the mouse pointer relatively to the main window:
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;
AmigaBASIC
MOUSE ON
WHILE 1
m=MOUSE(0)
PRINT MOUSE(1),MOUSE(2)
WEND
AppleScript
System Events can report the position of the currently active window. The mouse's location is retrieved with help from AppleScriptObjC. This will be relative to the bottom-left corner of the screen. Therefore, we also retrieve the screen's height.
use framework "AppKit"
tell application id "com.apple.SystemEvents" to tell ¬
(the first process where it is frontmost) to ¬
set {x, y} to the front window's position
tell the current application
set H to NSHeight(its NSScreen's mainScreen's frame)
tell [] & its NSEvent's mouseLocation
set item 1 to (item 1) - x
set item 2 to H - (item 2) - y
set coords to it as point
end tell
end tell
log coords
- Output:
{187, 171}
AutoHotkey
The window may be an externally created window.
#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
with DllCall
Source: GetCursorPos @github by jNizM
GetCursorPos()
{
static POINT, init := VarSetCapacity(POINT, 8, 0) && NumPut(8, POINT, "Int")
if (DllCall("User32.dll\GetCursorPos", "Ptr", &POINT))
{
return, { 0 : NumGet(POINT, 0, "Int"), 1 : NumGet(POINT, 4, "Int") }
}
}
GetCursorPos := GetCursorPos()
MsgBox, % "GetCursorPos function`n"
. "POINT structure`n`n"
. "x-coordinate:`t`t" GetCursorPos[0] "`n"
. "y-coordinate:`t`t" GetCursorPos[1]
Source: GetPhysicalCursorPos @github by jNizM
GetPhysicalCursorPos()
{
static POINT, init := VarSetCapacity(POINT, 8, 0) && NumPut(8, POINT, "Int")
if (DllCall("User32.dll\GetPhysicalCursorPos", "Ptr", &POINT))
{
return, { 0 : NumGet(POINT, 0, "Int"), 1 : NumGet(POINT, 4, "Int") }
}
}
GetPhysicalCursorPos := GetPhysicalCursorPos()
MsgBox, % "GetPhysicalCursorPos function`n"
. "POINT structure`n`n"
. "x-coordinate:`t`t" GetPhysicalCursorPos[0] "`n"
. "y-coordinate:`t`t" GetPhysicalCursorPos[1]
BBC BASIC
The mouse coordinates are relative to the bottom-left corner of the BBC BASIC main output window:
MOUSE xmouse%, ymouse%, buttons%
PRINT xmouse%, ymouse%
C
#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;
}
C++
Mouse pointers are part of the window manager system, and are therefore highly platform dependent.
This example works under a Windows operating system.
#include <iostream>
#include <windows.h>
int main() {
POINT MousePoint;
if ( GetCursorPos(&MousePoint) ) {
std::cout << MousePoint.x << ", " << MousePoint.y << std::endl;
}
}
- Output:
726, 506
c_sharp
Writes the absolute Mouse Position of the Screen into the Console
using System;
using System.Windows.Forms;
static class Program
{
[STAThread]
static void Main()
{
Console.WriteLine(Control.MousePosition.X);
Console.WriteLine(Control.MousePosition.Y);
}
}
Clojure
(let [point (.. java.awt.MouseInfo getPointerInfo getLocation)] [(.getX point) (.getY point)])
Common Lisp
With the ltk library.
(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))
This prints a lot of events of the form
#S(EVENT :X 0 :Y 85 :KEYCODE ?? :CHAR ?? :WIDTH ?? :HEIGHT ?? :ROOT-X 700 :ROOT-Y 433 :MOUSE-BUTTON ??)
The #S
indicates we get a structure, so we can access the x position with (event-x event)
.
Delphi
Shows mouse-position on a label on the form.
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
lblMousePosition.Caption := ('X:' + IntToStr(X) + ', Y:' + IntToStr(Y));
end;
Delphi Console Program
The following program will help capture the mouse position with the help of Windows and classes units.
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.
EasyLang
move 10 80
on mouse_move
clear
drawgrid
text mouse_x & " " & mouse_y
.
EchoLisp
When the plot library is loaded, the mouse position - relative to the plotting area coordinates, is displayed inside the info panel.
(lib 'plot)
(plot-x-minmax 10) ; set logical dimensions of plotting area
(plot-y-minmax 100)
→ (("x" 0 10) ("y" 0 100))
;; press ESC to see the canvas
;; the mouse position is displayed as , for example, [ x: 5.6 y : 88.7]
;; 0 <= x <= 10, 0 <= y <= 100
--Neo.abhinav 17:00, 6 May 2011 (UTC)
Elm
import Graphics.Element exposing (Element, show)
import Mouse
main : Signal Element
main =
Signal.map show Mouse.position
Emacs Lisp
For Emacs' own frames (which is what Emacs calls its window system windows), the frame the mouse is over and where the mouse is within that frame can be obtained with
(mouse-pixel-position)
;; => (FRAME . (X . Y))
Or mouse-position
for characters instead of pixels.
Works when the mouse is over any Emacs frame, not just when that frame is the active focused window.
There's no particularly easy way to inquire about a non-Emacs focused window, only generic X11 or similar approaches run externally.
ERRE
This example program, taken from distribution disk, shows the mouse position in a text field at the bottom-right corner and updates when the mouse is moved.
!
! MOUSE WITH 'MOUSE.LIB' LIBRARY
!
PROGRAM MOUSE
!$KEY
!$INCLUDE="PC.LIB"
!$INCLUDE="MOUSE.LIB"
PROCEDURE GETMONITORTYPE(->MONITOR$)
!$RCODE="DEF SEG=0"
STATUS=PEEK($463)
!$RCODE="DEF SEG"
MONITOR$=""
IF STATUS=$B4 THEN
!$RCODE="STATUS=(INP(&H3BA) AND &H80)"
FOR DELAYLOOP=1 TO 30000 DO
!$RCODE="XX=((INP(&H3BA) AND &H80)<>STATUS)"
IF XX THEN MONITOR$="HERC" END IF
END FOR
IF MONITOR$="" THEN MONITOR$="MONO" END IF
ELSE
REGAX%=$1A00
EXECUTEASM($10)
IF (REGAX% AND $FF)=$1A THEN
MONITOR$="VGA"
ELSE
REGAX%=$1200 REGBX%=$10
EXECUTEASM($10)
IF (REGBX% AND $FF)=$10 THEN
MONITOR$="CGA"
ELSE
MONITOR$="EGA"
END IF
END IF
END IF
END PROCEDURE
BEGIN
INITASM
GETMONITORTYPE(->MONITOR$)
COLOR(7,0)
CLS
LOCATE(1,50) PRINT("MONITOR TYPE ";MONITOR$)
MOUSE_RESETANDSTATUS(->STATUS,BUTTONS)
IF STATUS<>-1 THEN
BEEP
CLS
PRINT("MOUSE DRIVER NOT INSTALLED OR MOUSE NOT FOUND")
REPEAT
GET(IN$)
UNTIL IN$<>""
ELSE
MOUSE_SETEXTCURSOR
MOUSE_SETCURSORLIMITS(8,199,0,639)
MOUSE_SETSENSITIVITY(30,30,50)
MOUSE_SHOWCURSOR
REPEAT
OLDX=X OLDY=Y
MOUSE_GETCURSORPOSITION(->X,Y,LEFT%,RIGHT%,BOTH%,MIDDLE%)
GET(IN$)
COLOR(15,0)
LOCATE(1,2)
PRINT("X =";INT(X/8)+1;" Y =";INT(Y/8)+1;" ";)
IF LEFT% THEN LOCATE(1,37) COLOR(10,0) PRINT("LEFT";) END IF
IF RIGHT% THEN LOCATE(1,37) COLOR(12,0) PRINT("RIGHT";) END IF
IF MIDDLE% THEN LOCATE(1,37) COLOR(14,0) PRINT("MIDDLE";) END IF
IF NOT RIGHT% AND NOT LEFT% AND NOT MIDDLE% THEN
LOCATE(1,37) PRINT(" ";)
END IF
IF NOT (X=OLDX AND Y=OLDY) THEN MOUSE_SHOWCURSOR END IF
UNTIL IN$=CHR$(27)
END IF
MOUSE_HIDECURSOR
CLS
END PROGRAM
F#
Have to do a lot of interop here. Primarily because the active window may not be a .NET form/control. If the question was for the point relative to the current window, life would be much simpler.
open System.Windows.Forms
open System.Runtime.InteropServices
#nowarn "9"
[<Struct; StructLayout(LayoutKind.Sequential)>]
type POINT =
new (x, y) = { X = x; Y = y }
val X : int
val Y : int
[<DllImport("user32.dll")>]
extern nativeint GetForegroundWindow();
[<DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true, ExactSpelling=true)>]
extern int ScreenToClient(nativeint hWnd, POINT &pt);
let GetMousePosition() =
let hwnd = GetForegroundWindow()
let pt = Cursor.Position
let mutable ptFs = new POINT(pt.X, pt.Y)
ScreenToClient(hwnd, &ptFs) |> ignore
ptFs
Factor
Works only in the graphical listener. Replaces the text in the button with the relative and absolute coordinates of the mouse
: 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. ;
FreeBASIC
Also includes the state of the mouse wheel and mouse buttons, since these are provided by the same subroutine that provides the cursor position.
type MOUSE
'mouse position, button state, wheel state
x as integer
y as integer
buttons as integer
wheel as integer
end type
screen 12
dim as MOUSE mouse
while inkey=""
locate 1,1
getmouse(mouse.x, mouse.y, mouse.wheel, mouse.buttons)
if mouse.x < 0 then
print "Mouse out of window. "
print " "
print " "
else
print "Mouse position : ", mouse.x, mouse.y, " "
print "Buttons clicked: ";
print Iif( mouse.buttons and 1, "Left ", " " );
print Iif( mouse.buttons and 2, "Right ", " " );
print Iif( mouse.buttons and 4, "Middle ", " " )
print "Wheel scrolls: ", mouse.wheel," "
end if
wend
FutureBasic
subclass window 1, @"Click somewhere in the window"
void local fn DoDialog( ev as long )
select ( ev )
case _windowMouseDown
CGPoint pt = fn EventLocationInWindow
cls : printf @"%.0fx, %.0fy",pt.x,pt.y
end select
end fn
on dialog fn DoDialog
HandleEvents
Gambas
In gambas, the position of the pointer can only be determined when the click button is held down. A window with a drawing area is required, because this is the only widget that can track pointer movement within gambas.
PUBLIC SUB Form1_MouseMove()
PRINT mouse.X
PRINT Mouse.Y
END
Go
The active window may be externally created.
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)
}
}
- Output:
A first run after placing mouse cursor inside active window:
The active window's top left corner is at (547, 167) Its width is 792 and its height is 506 The screen location of the mouse cursor is (949, 446) The window location of the mouse cursor is (402, 279)
A second run after moving mouse cursor outside active window:
The active window's top left corner is at (547, 167) Its width is 792 and its height is 506 The screen location of the mouse cursor is (334, 639) The mouse cursor is outside the active window
Groovy
Based on Java solution:
1.upto(5) {
Thread.sleep(1000)
def p = java.awt.MouseInfo.pointerInfo.location
println "${it}: x=${p.@x} y=${p.@y}"
}
Sample output:
1: x=857 y=0 2: x=765 y=447 3: x=0 y=535 4: x=715 y=283 5: x=1335 y=83
HicEst
Mouse click positions for windows created internally. X and Y are in units of current xy axes (optional: invisible).
WINDOW(WINdowhandle=handle)
AXIS(WINdowhandle=handle, MouSeCall=Mouse_Callback, MouSeX=X, MouSeY=Y)
END
SUBROUTINE Mouse_Callback()
WRITE(Messagebox, Name) X, Y
END
Icon and Unicon
In Icon/Unicon the mouse position may be tracked between button presses for any window created by the program. The following code snippet taken from the Icon Graphics Book on page 197-198 shows how to track the mouse.
Java
The mouse position can be checked at any time by calling
Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
This returns a point on the entire screen, rather than relative to a particular window. This call can be combined with getLocation()
from any Component
(including a Frame
, which is a window) to get the location relative to that Component
.
JavaScript
In a browser environment, it's impossible to actually get the cursor position at the specific moment. You must wait for user input (movement, click, etc). One of many ways to add an event listener:
document.addEventListener('mousemove', function(e){
var position = { x: e.clientX, y: e.clientY }
}
In the above example, the window may not be external. It must in fact be a web browser window, which runs the script.
Julia
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)
Kotlin
// version 1.1.2
import java.awt.MouseInfo
fun main(args: Array<String>) {
(1..5).forEach {
Thread.sleep(1000)
val p = MouseInfo.getPointerInfo().location // gets screen coordinates
println("${it}: x = ${"%-4d".format(p.x)} y = ${"%-4d".format(p.y)}")
}
}
Sample output:
- Output:
1: x = 752 y = 483 2: x = 1112 y = 478 3: x = 1331 y = 511 4: x = 269 y = 562 5: x = 247 y = 505
Liberty BASIC
This example gets the mouse position based on the active window. Click on other windows to get relative mouse position based on those windows.
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
Lingo
put _mouse.mouseLoc
-- point(310, 199)
xTalk
-- Method 1:
-- this script in either the stack script or the card script to get position relative to the current stack window
on mouseMove pMouseH,pMouseV
put pMouseH,pMouse
end mouseMove
-- Method 2:
-- this script can go anywhere to get current position relative to the current stack window
put mouseLoc()
-- Method 3:
-- this script can go anywhere to get current position relative to the current stack window
put the mouseLoc
-- Method 4:
-- this script can go anywhere to get current position relative to the current window
put the mouseH &","& the mouseV
To get the mousePosition relative to the current screen instead of relative to the current stack window use the screenMouseLoc keyword
example results:
117,394 -- relative to current window
117,394 -- relative to current window
117,394 -- relative to current window
148,521 -- relative to current screen
LiveCode Builder
LiveCode Builder (LCB) is a slightly lower level, strictly typed variant of LiveCode Script (LCS) used for making add-on extensions to LiveCode Script
-- results will be a point array struct like [117.0000,394.0000] relative to the current widget's view port
use com.livecode.widget -- include the required module
--- in your handler:
variable tPosition as Point -- type declaration, tPosition is a point array struct
put the mouse position into tPosition
variable tRect as Rectangle -- type declaration, tRect is a rect array struct, something like [0,1024,0,768]
put my bounds into tRect
if tPosition is within tRect then
log "mouse position is within the widget bounds"
end if
Logo
show mousepos ; [-250 250]
M2000 Interpreter
Module Checkit {
\\ works when console is the active window
\\ pressing right mouse button exit the loop
While mouse<>2
Print mouse.x, mouse.y
End While
\\ end of part one, now we make a form with title Form1 (same name as the variable name)
Declare Form1 Form
Layer Form1 {
window 16, 10000,8000 ' 16pt font at maximum 10000 twips x 8000 twips
cls #335522, 1 \\ from 2nd line start the split screen (for form's layer)
pen 15 ' white
}
Function Form1.MouseMove {
Read new button, shift, x, y ' we use new because call is local, same scope as Checkit.
Layer Form1 {
print x, y, button
refresh
}
}
Function Form1.MouseDown {
Read new button, shift, x, y
\\ when we press mouse button we print in console
\\ but only the first time
print x, y, button
refresh
}
\\ open Form1 as modal window above console
Method Form1, "Show", 1
Declare Form1 Nothing
}
CheckIt
Mathematica/Wolfram Language
MousePosition["WindowAbsolute"]
MATLAB
get(0,'PointerLocation')
MAXScript
Creates a window on the screen and shows mouse position as it moves.
try destroydialog mousePos catch ()
rollout mousePos "Mouse position" width:200
(
label mousePosText "Current mouse position:" pos:[0,0]
label mousePosX "" pos:[130,0]
label mousePosSep "x" pos:[143,0]
label mousePosY "" pos:[160,0]
timer updateTimer interval:50 active:true
on updateTimer tick do
(
mousePosX.text = (mouse.screenpos.x as integer) as string
mousePosY.text = (mouse.screenpos.y as integer) as string
)
)
createdialog mousepos
MiniScript
print mouse.x, mouse.y
Nanoquery
import Nanoquery.Util.Windows
// a function to handle the mouse moved event
def mouse_moved($caller, $e)
println "(" + $e.getX() + ", " + $e.getY() + ")"
end
// create a window, set the handler for mouse moved, and show it
w = new("Window")
w.setSize(500, 500)
w.setHandler(w.mouseMoved, mouse_moved)
w.show()
Nim
import gintro/[glib, gobject, gtk, gio]
import gintro/gdk except Window
#---------------------------------------------------------------------------------------------------
proc onButtonPress(window: ApplicationWindow; event: Event; data: pointer): bool =
echo event.getCoords()
result = true
#---------------------------------------------------------------------------------------------------
proc activate(app: Application) =
## Activate the application.
let window = app.newApplicationWindow()
window.setTitle("Mouse position")
window.setSizeRequest(640, 480)
discard window.connect("button-press-event", onButtonPress, pointer(nil))
window.showAll()
#———————————————————————————————————————————————————————————————————————————————————————————————————
let app = newApplication(Application, "Rosetta.MousePosition")
discard app.connect("activate", activate)
discard app.run()
- Output:
Sample output:
(136.631591796875, 91.27691650390625) (308.6276245117188, 148.8543090820312) (387.9143676757812, 332.2145385742188) (191.778076171875, 368.4205932617188) (76.43170166015625, 418.7800903320312) (298.4449462890625, 451.6014404296875) (9.709716796875, 11.10366821289062) (636.892333984375, 476.888671875) (4.505615234375, 4.832611083984375) (631.4815673828125, 5.864105224609375) (6.33782958984375, 475.9739379882812)
OCaml
equivalent to the C example, uses the Xlib binding ocaml-xlib
open Xlib
let () =
let d = xOpenDisplay "" in
(* ask for active window (no error check);
the client must be freedesktop compliant *)
let _, _, _, _, props =
xGetWindowProperty_window d
(xDefaultRootWindow d)
(xInternAtom d "_NET_ACTIVE_WINDOW" true)
0 1 false AnyPropertyType
in
let _, _, _, child, _ = xQueryPointer d props in
begin match child with
| Some(_, childx, childy) ->
Printf.printf "relative to active window: %d,%d\n%!" childx childy;
| None ->
print_endline "the pointer is not on the same screen as the specified window"
end;
xCloseDisplay d;
;;
Octave
To get the X,Y coordinates of N mouse clicks in the current figure, one can use this:
[X, Y, BUTTONS] = ginput(N);
Example:
>> [X, Y, BUTTONS] = ginput(4) X = 0.16113 0.26300 0.44343 0.23164 Y = 0.87357 0.87596 0.73330 0.54911 BUTTONS = 1 3 1 2
Odin
package main
import "core:fmt"
import "vendor:sdl2"
main :: proc() {
using sdl2
window: ^Window = ---
renderer: ^Renderer = ---
event: Event = ---
Init(INIT_VIDEO)
CreateWindowAndRenderer(
640, 480,
WINDOW_SHOWN,
&window, &renderer
)
SetWindowTitle(window, "Empty window")
RenderPresent(renderer)
for event.type != .QUIT {
if event.type == .MOUSEMOTION {
using event.motion
fmt.printf("x=%d y=%d\n", x, y)
}
Delay(10)
PollEvent(&event)
}
DestroyRenderer(renderer)
DestroyWindow(window)
Quit()
}
Oz
Repeatedly shows the mouse coordinates relative to the foremost window of the application.
declare
[QTk] = {Module.link ['x-oz://system/wp/QTk.ozf']}
WindowClosed = {NewCell false}
Label
Window = {QTk.build
td(action:proc {$} WindowClosed := true {Window close} end
label(text:"" handle:Label))}
in
{Window show}
for while:{Not @WindowClosed} do
TopmostWindow = {List.last {String.tokens {Tk.return wm(stackorder '.')} & }}
Winfo = {Record.mapInd winfo(rootx:_ rooty:_ pointerx:_ pointery:_)
fun {$ I _}
{Tk.returnInt winfo(I TopmostWindow)}
end}
in
{Label set(text:"x: "#(Winfo.pointerx - Winfo.rootx)
#", y: "#(Winfo.pointery - Winfo.rooty))}
{Delay 250}
end
Pebble
;mouse demonstration
;compile with Pebble
;for textmode x86 DOS
;requires mouse driver
program examples\mouse
use mouse.inc
data
int mousex[0]
int mousey[0]
int mouseb[0]
int speed[0]
int i[0]
begin
echo "Enter 1-200 for slow/DOS/emulated machines."
echo "Enter 500-20000 for faster/Windows machines."
input [speed]
cls
call showmouse
label mainloop
;clear mouse coordinates
cursor 0, 0
echo " "
echo " "
;get and display mouse coordinates
call readmouse
cursor 0, 0
echo [mousey]
crlf
echo [mousex]
;display exit button
cursor 76, 0
echo "[X]"
;check if exit button has been clicked
if [mouseb] = 1 & [mousex] >= 76 & [mousex] <= 79 & [mousey] = 0 then
kill
endif
;loop 100 times since some machines do not support the WAIT command
[i] = 0
label delay
+1 [i]
wait 1
if [i] < [speed] then delay
goto mainloop
end
Perl
The following code will use the SDL module, a wrapper for the libSDL C-library. When you move the mouse over the created window, the mouse position get printed and the program terminates.
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;
- Output:
x=15 y=304
Phix
The following example shows three labels being updated with the mouse position.
The globalmotion label is updated whenever the mouse moves anywhere within the window, but not outside it.
The canvasmotion label is updated whenever the mouse moves within the canvas, but not elsewhere in the window (or beyond).
The timer label is updated every three seconds and gets mouse positions anywhere on the whole screen, whether it moves or not.
Note that canvasmotion coordinates are relative to the top left of the canvas, whereas the other two are absolute.
-- demo\rosetta\Mouse_position.exw
include pGUI.e
Ihandle global_lbl, canvas_lbl, timer_lbl
function globalmotion_cb(integer x, integer y, atom /*pStatus*/)
IupSetStrAttribute(global_lbl,"TITLE","globalmotion_cb %d, %d",{x,y})
return IUP_DEFAULT
end function
function canvas_motion_cb(Ihandle /*canvas*/, integer x, integer y, atom pStatus)
IupSetStrAttribute(canvas_lbl,"TITLE","canvasmotion_cb %d, %d",{x,y})
return IUP_DEFAULT;
end function
function OnTimer(Ihandle /*ih*/)
integer {x,y} = IupGetIntInt(NULL,"CURSORPOS")
IupSetStrAttribute(timer_lbl,"TITLE","timer %d, %d",{x,y})
return IUP_IGNORE
end function
procedure main()
Ihandle separator1, separator2,
canvas, frame_1, frame_2,
dialog
IupOpen()
global_lbl = IupLabel("Move the mouse anywhere on the window","EXPAND=HORIZONTAL")
separator1 = IupLabel(NULL,"SEPARATOR=HORIZONTAL")
canvas_lbl = IupLabel("Move the mouse anywhere on the canvas","EXPAND=HORIZONTAL")
separator2 = IupLabel(NULL,"SEPARATOR=HORIZONTAL")
timer_lbl = IupLabel("This one runs on a three second timer","EXPAND=HORIZONTAL")
frame_1 = IupFrame(IupVbox({global_lbl,
separator1,
canvas_lbl,
separator2,
timer_lbl}),
"TITLE=IupLabel, SIZE=200x")
canvas = IupCanvas("MOTION_CB", Icallback("canvas_motion_cb"),
"EXPAND=HORIZONTAL, RASTERSIZE=200x200")
frame_2 = IupFrame(canvas, "TITLE=IupCanvas")
dialog = IupDialog(IupHbox({frame_1,frame_2}, "MARGIN=5x5, GAP=5"))
IupSetAttribute(dialog,"TITLE","Mouse motion");
IupSetGlobal("INPUTCALLBACKS", "Yes");
IupSetGlobalFunction("GLOBALMOTION_CB", Icallback("globalmotion_cb"));
Ihandle hTimer = IupTimer(Icallback("OnTimer"), 3000)
IupShow(dialog)
IupMainLoop()
IupClose()
end procedure
main()
PicoLisp
The following works in an XTerm window. After calling (mousePosition), click into the current terminal window. The returned value is (X . Y), where X is the column and Y the line number.
(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
- Output:
: (mousePosition) -> (7 . 3)
PureBasic
The mouse position can be obtained by these two commands:
x = WindowMouseX(#MyWindow)
y = WindowMouseY(#MyWindow)
This example repeatedly shows the mouse coordinates relative to the window created in the application.
#MyWindow = 0
#Label_txt = 0
#MousePos_txt = 1
If OpenWindow(#MyWindow,0,0,200,200,"Test",#PB_Window_SystemMenu)
TextGadget(#Label_txt,0,0,100,20,"Mouse Position (x,y):",#PB_Text_Right)
TextGadget(#MousePos_txt,120,0,60,20,"()")
Repeat
Repeat
event = WaitWindowEvent(10)
If event = #PB_Event_CloseWindow
Break 2 ;exit program
EndIf
Until event = 0
x = WindowMouseX(#MyWindow)
y = WindowMouseY(#MyWindow)
SetGadgetText(#MousePos_txt,"(" + Str(x) + "," + Str(y) + ")")
ForEver
EndIf
Processing
void setup(){
size(640, 480);
}
void draw(){
// mouseX and mouseY provide the current mouse position
ellipse(mouseX, mouseY, 5, 5); // graphic output example
println("x:" + mouseX + " y:" + mouseY);
}
Processing Python mode
def setup():
size(640, 480)
def draw():
# mouseX and mouseY provide the current mouse position
ellipse(mouseX, mouseY, 5, 5) # graphic output example
println("x:{} y:{}".format(mouseX, mouseY))
Python
Mouse position using Tkinter graphics library nearly universally included in installations of Python.
There are other alternatives but they are platform specific.
Shows position of mouse while it is over the program windows and
changes color of window when mouse is near (<10) hot spot 100,100.
Code is based on post in Daniweb: http://www.daniweb.com/forums/post616327.html#post616327 by ZZucker
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()
#simple way of ,get cursor xy data
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()
Racket
The mouse position can be queried at any time with a function in a GUI context.
#lang racket/gui
(define-values [point _] (get-current-mouse-state))
(send point get-x)
(send point get-y)
Raku
(formerly Perl 6)
use java::awt::MouseInfo:from<java>;
given MouseInfo.getPointerInfo.getLocation {
say .getX, 'x', .getY;
}
An implementation that will work on any X11 windowing system. Reports mouse position, window ID# and window name for whichever window the mouse pointer is over. Automatically moves mouse for hands-off testing purposes.
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 '';
Ring
In the next example the user can move a label using the mouse The movement procedure uses the mouse position information
Load "guilib.ring"
lPress = false
nX = 0
nY = 0
new qApp {
win1 = new qWidget()
{
setWindowTitle("Move this label!")
setGeometry(100,100,400,400)
setstylesheet("background-color:white;")
Label1 = new qLabel(Win1){
setGeometry(100,100,200,50)
setText("Welcome")
setstylesheet("font-size: 30pt")
myfilter = new qallevents(label1)
myfilter.setEnterevent("pEnter()")
myfilter.setLeaveevent("pLeave()")
myfilter.setMouseButtonPressEvent("pPress()")
myfilter.setMouseButtonReleaseEvent("pRelease()") myfilter.setMouseMoveEvent("pMove()")
installeventfilter(myfilter)
}
show()
}
exec()
}
Func pEnter
Label1.setStyleSheet("background-color: purple; color:white;font-size: 30pt;")
Func pLeave
Label1.setStyleSheet("background-color: white; color:black;font-size: 30pt;")
Func pPress
lPress = True
nX = myfilter.getglobalx()
ny = myfilter.getglobaly()
Func pRelease
lPress = False
pEnter()
Func pMove
nX2 = myfilter.getglobalx()
ny2 = myfilter.getglobaly()
ndiffx = nX2 - nX
ndiffy = nY2 - nY
if lPress
Label1 {
move(x()+ndiffx,y()+ndiffy)
setStyleSheet("background-color: Green;
color:white;font-size: 30pt;")
nX = nX2
ny = nY2
}
ok
Ruby
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
Rust
Prints current location of the mouse cursor relative to any active window. This example relies on the Windows API.
// rustc 0.9 (7613b15 2014-01-08 18:04:43 -0800)
use std::libc::{BOOL, HANDLE, LONG};
use std::ptr::mut_null;
type HWND = HANDLE;
#[deriving(Eq)]
struct POINT {
x: LONG,
y: LONG
}
#[link_name = "user32"]
extern "system" {
fn GetCursorPos(lpPoint:&mut POINT) -> BOOL;
fn GetForegroundWindow() -> HWND;
fn ScreenToClient(hWnd:HWND, lpPoint:&mut POINT);
}
fn main() {
let mut pt = POINT{x:0, y:0};
loop {
std::io::timer::sleep(100); // sleep duration in milliseconds
let pt_prev = pt;
unsafe { GetCursorPos(&mut pt) };
if pt != pt_prev {
let h = unsafe { GetForegroundWindow() };
if h == mut_null() { continue }
let mut pt_client = pt;
unsafe { ScreenToClient(h, &mut pt_client) };
println!("x: {}, y: {}", pt_client.x, pt_client.y);
}
}
}
- Output:
x: 550, y: 614 x: 650, y: 248 x: 612, y: 0 x: 620, y: 0 x: 405, y: 0 x: 0, y: 0 ^C
Scala
import java.awt.MouseInfo
object MousePosition extends App {
val mouseLocation = MouseInfo.getPointerInfo.getLocation
println (mouseLocation)
}
Seed7
The functions pointerXPos and pointerYPos from the graph.s7i library determine the actual X and Y position of the mouse pointer, relative to the given window:
xPos := pointerXPos(curr_win);
yPos := pointerYPos(curr_win);
Smalltalk
Sending the message position to the activeHand of the World returns a Point object:
World activeHand position. " (394@649.0)"
Standard ML
Works with PolyML
open XWindows ;
val dp = XOpenDisplay "" ;
val w = XCreateSimpleWindow (RootWindow dp) origin (Area {x=0,y=0,w=400,h=300}) 3 0 0xffffff ;
XMapWindow w;
val (focus,_)=( Posix.Process.sleep (Time.fromReal 2.0); (* time to move from interpreter + activate arbitrary window *)
XGetInputFocus dp
) ;
XQueryPointer focus ;
XQueryPointer w;
result: position wrt root window and active window, resp wrt root window and window w
val it = (true, Drawable, Drawable, XPoint {x = 1259, y = 979}, XPoint {x = 236, y = 105}, []): bool * Drawable * Drawable * XPoint * XPoint * Modifier list val it = (true, Drawable, Drawable, XPoint {x = 1259, y = 979}, XPoint {x = 1056, y = 817}, []): bool * Drawable * Drawable * XPoint * XPoint * Modifier list
Tcl
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"
screen coordinates
package require Tk
puts "monitor/display coordinate x = [winfo pointerx .]"
Uxntal
|00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1
|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &pad $3 &scrollx $2 &scrolly $2
|0100
;on-mouse .Mouse/vector DEO2
BRK
@on-mouse
.Mouse/x DEI2 print-hex2
#20 .Console/write DEO
.Mouse/y DEI2 print-hex2
#0a .Console/write DEO
BRK
@print-hex
DUP #04 SFT print-digit #0f AND print-digit
JMP2r
@print-hex2
SWP print-hex print-hex
JMP2r
@print-digit
DUP #09 GTH #27 MUL ADD #30 ADD .Console/write DEO
JMP2r
Vala
// GTK 4
public class Example : Gtk.Application {
public Example() {
Object(application_id: "my.application",
flags: ApplicationFlags.FLAGS_NONE);
activate.connect(() => {
var window = new Gtk.ApplicationWindow(this);
var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 20);
var button = new Gtk.Button.with_label("Get Cursor Position");
button.clicked.connect((a) => {
double x, y;
var device_pointer= window.get_display().get_default_seat().get_pointer();
window.get_surface().get_device_position(device_pointer, out x, out y, null);
label.set_text(x.to_string() + "," + y.to_string());
});
box.append(label);
box.append(button);
window.set_child(box);
window.present();
});
}
public static int main(string[] argv) {
return new Example().run(argv);
}
}
Visual Basic
There are two methods for determining where the mouse pointer is. The first only works when the pointer is actually over the window containing the code. This actually works for any control that has a MouseMove event, but it doesn't work if the pointer is over anything else, including controls on the form (so if the pointer is over a button on the current form, the event will only fire for the button, not the form).
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'X and Y are in "twips" -- 15 twips per pixel
Me.Print "X:" & X
Me.Print "Y:" & Y
End Sub
The second method uses the Windows API,
and can be easily translated to any language that can make API calls.
This example uses a Timer
control to check the mouse position.
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
'X and Y are in pixels, with (0,0) being the top left corner of the primary display
X As Long
Y As Long
End Type
Private Pt As POINTAPI
Private Sub Timer1_Timer()
GetCursorPos Pt
Me.Cls
Me.Print "X:" & Pt.X
Me.Print "Y:" & Pt.Y
End Sub
Wren
import "dome" for Window
import "graphics" for Canvas
import "input" for Mouse
class Game {
static init() {
Window.title = "Mouse position"
Canvas.resize(400, 400)
Window.resize(400, 400)
// get initial mouse coordinates
__px = Mouse.x
__py = Mouse.y
__ticks = 0
System.print("The coordinates of the mouse relative to the canvas are:")
}
static update() {
__ticks = __ticks + 1
if (__ticks%60 == 0) {
// get current mouse coordinates
var cx = Mouse.x
var cy = Mouse.y
// if it's moved in the last second, report new position
if (cx != __px || cy != __py) {
System.print([cx, cy])
__px = cx
__py = cy
}
}
}
static draw(alpha) {}
}
- Output:
Sample output:
The coordinates of the mouse relative to the canvas are: [134, 197] [229, 29] [250, 62] [266, 286] [101, 319] [45, 314] [6, 173] [269, 0]
XPL0
GetMousePosition(0) = X coordinate; 1 = Y coordinate. For video modes $0..$E and $13 the maximum coordinates are 639x199, minus the size of the pointer. For modes $F..$12 the coordinates are the same as the pixels. VESA graphic modes are (usually) 639x479 regardless of the resolution. For 80-column text modes divide the mouse coordinates by 8 to get the character cursor position.
The mouse cursor location is always relative to the upper-left corner of the screen. A window may be externally created ... using a fair amount of code because the version of XPL0 used with these Rosetta Code examples does not make Windows applications (however see "Simple windowed application").
include c:\cxpl\stdlib;
if not OpenMouse then Text(0, "A mouse is required")
else [ShowMouse(true);
IntOut(0, GetMousePosition(0)); ChOut(0, ^,);
IntOut(0, GetMousePosition(1)); CrLf(0);
]
- Example output:
320,96
- Programming Tasks
- GUI
- Testing
- Hardware
- Pointing devices
- ACL2/Omit
- AWK/Omit
- Befunge/Omit
- Brainf***/Omit
- GolfScript/Omit
- GUISS/Omit
- Logtalk/Omit
- Lotus 123 Macro Scripting/Omit
- Maxima/Omit
- ML/I/Omit
- PARI/GP/Omit
- PHP/Omit
- PostScript/Omit
- R/Omit
- SQL PL/Omit
- TI-83 BASIC/Omit
- TI-89 BASIC/Omit
- UNIX Shell/Omit
- ZX Spectrum Basic/Omit
- 8086 Assembly
- ActionScript
- Ada
- GTK
- GtkAda
- GLib
- AmigaBASIC
- AppleScript
- AutoHotkey
- BBC BASIC
- C
- Xlib
- C++
- C sharp
- Clojure
- Common Lisp
- Delphi
- EasyLang
- EchoLisp
- Elm
- Emacs Lisp
- ERRE
- F Sharp
- Factor
- FreeBASIC
- FutureBasic
- Gambas
- Go
- RobotGo
- Groovy
- HicEst
- Icon
- Unicon
- Java
- JavaScript
- Julia
- Kotlin
- Liberty BASIC
- Lingo
- XTalk
- LiveCode Builder
- Logo
- M2000 Interpreter
- Mathematica
- Wolfram Language
- MATLAB
- MAXScript
- MiniScript
- Nanoquery
- Nim
- Gintro
- OCaml
- Octave
- Odin
- Oz
- Pebble
- Perl
- Perl/SDL
- Phix
- Phix/pGUI
- PicoLisp
- PureBasic
- Processing
- Processing Python mode
- Python
- Python Tkinter module (Tk 8.5)
- Racket
- Raku
- Ring
- Ruby
- Shoes
- Rust
- Scala
- Seed7
- Smalltalk
- Standard ML
- Tcl
- Tk
- Uxntal
- Vala
- Visual Basic
- Wren
- DOME
- XPL0