Jump to content

Mouse position: Difference between revisions

m
No edit summary
 
(9 intermediate revisions by 7 users not shown)
Line 272:
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#}}==
Line 355 ⟶ 376:
=={{header|EasyLang}}==
 
[https://easylang.dev/show/#cod=y80vS1UwNFCwMODKz1PIzS8tTo3PBYpxKSgoJOekJhaBGClFieXpRZkpIHZJakUJVF2FgpqCEhCqQfmVXHpcXAA= Run it]
[https://easylang.online/ide/#run=on%20mouse_move%0A%20%20clear%0A%20%20text%20mouse_x%20%26%20%22%20%22%20%26%20mouse_y%0A.%0A Run it]
 
<syntaxhighlight lang="text">on mouse_move
move 10 80
clear
on mouse_move
text mouse_x & " " & mouse_y
clear
.</syntaxhighlight>
drawgrid
text mouse_x & " " & mouse_y
.
</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 1,027 ⟶ 1,052:
2
</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}}==
Line 1,051 ⟶ 1,114:
{Delay 250}
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}}==
Line 1,491 ⟶ 1,627:
<syntaxhighlight lang="tcl">package require Tk
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}}==
Line 1,528 ⟶ 1,720:
=={{header|Wren}}==
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "dome" for Window
import "graphics" for Canvas
import "input" for Mouse
2,063

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.