Mouse position: Difference between revisions

Content deleted Content added
m Category:Hardware / move Category to top
m {{out}}
Line 560: Line 560:
$app->run;
$app->run;
</lang>
</lang>
{{out}}
Output:
<pre>x=15 y=304</pre>
<pre>x=15 y=304</pre>


Line 589: Line 589:
(- (char (key)) 32) ) )
(- (char (key)) 32) ) )
(prin "^[[?9l") ) ) # Mouse reporting off</lang>
(prin "^[[?9l") ) ) # Mouse reporting off</lang>
{{out}}
Output:
<pre>: (mousePosition)
<pre>: (mousePosition)
-> (7 . 3)</pre>
-> (7 . 3)</pre>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
The mouse position can be obtained by these two commands.
The mouse position can be obtained by these two commands:
<lang PureBasic>x = WindowMouseX(#MyWindow)
<lang PureBasic>x = WindowMouseX(#MyWindow)
y = WindowMouseY(#MyWindow)</lang>
y = WindowMouseY(#MyWindow)</lang>
This example repeatedly shows the mouse coordinates relative to the window created in the application.
This example repeatedly shows the mouse coordinates
relative to the window created in the application.
<lang PureBasic>#MyWindow = 0
<lang PureBasic>#MyWindow = 0
#Label_txt = 0
#Label_txt = 0
Line 618: Line 619:
ForEver
ForEver
EndIf</lang>
EndIf</lang>

=={{header|Python}}==
=={{header|Python}}==


Line 649: Line 651:
root.mainloop()
root.mainloop()
</lang>
</lang>

***********************************************************************************
***********************************************************************************
<lang python>
<lang python>
Line 667: Line 670:


=={{header|Scala}}==
=={{header|Scala}}==

[[Category:Scala Implementations]]
{{libheader|Scala}}<lang scala>import java.awt.MouseInfo
{{libheader|Scala}}<lang scala>import java.awt.MouseInfo
object MousePosition extends App {
object MousePosition extends App {
Line 778: Line 781:
There are two methods for determining where the mouse pointer is.
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.
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).
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).
<lang vb>Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
<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
Line 785: Line 792:
End Sub</lang>
End Sub</lang>


The second method uses the [[wp:Windows API|Windows API]], and can be easily translated to any language that can make API calls.
The second method uses the [[wp:Windows API|Windows API]],
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.
<lang vb>Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
<lang vb>Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Line 806: Line 814:
=={{header|XPL0}}==
=={{header|XPL0}}==
GetMousePosition(0) = X coordinate; 1 = Y coordinate.
GetMousePosition(0) = X coordinate; 1 = Y coordinate.
For video modes
For video modes $0..$E and $13 the maximum coordinates are 639x199,
$0..$E and $13 the maximum coordinates are 639x199, minus the size of the pointer.
minus the size of the pointer.
For modes $F..$12 the coordinates are the same as the pixels.
For modes $F..$12 the coordinates are the same as the pixels.
VESA graphic modes are (usually) 639x479 regardless of the resolution.
VESA graphic modes are (usually) 639x479 regardless of the resolution.
Line 813: Line 821:
character cursor position.
character cursor position.


The mouse cursor location is always relative to the upper-left corner of
The mouse cursor location is always relative to the upper-left corner of the screen.
the screen. A window may be externally created ... using a fair amount of
A window may be externally created ... using a fair amount of
code because the version of XPL0 used with these Rosetta Code examples
code because the version of XPL0 used with these Rosetta Code examples
does not make Windows applications (however see "Simple windowed application").
does not make Windows applications (however see "Simple windowed application").