Mouse position: Difference between revisions

m
{{out}}
m (Category:Hardware / move Category to top)
m ({{out}})
Line 560:
$app->run;
</lang>
{{out}}
Output:
<pre>x=15 y=304</pre>
 
Line 589:
(- (char (key)) 32) ) )
(prin "^[[?9l") ) ) # Mouse reporting off</lang>
{{out}}
Output:
<pre>: (mousePosition)
-> (7 . 3)</pre>
 
=={{header|PureBasic}}==
The mouse position can be obtained by these two commands.:
<lang PureBasic>x = WindowMouseX(#MyWindow)
y = WindowMouseY(#MyWindow)</lang>
This example repeatedly shows the mouse coordinates relative to the window created in the application.
relative to the window created in the application.
<lang PureBasic>#MyWindow = 0
#Label_txt = 0
Line 618 ⟶ 619:
ForEver
EndIf</lang>
 
=={{header|Python}}==
 
Line 649 ⟶ 651:
root.mainloop()
</lang>
 
***********************************************************************************
<lang python>
Line 667 ⟶ 670:
 
=={{header|Scala}}==
 
[[Category:Scala Implementations]]
{{libheader|Scala}}<lang scala>import java.awt.MouseInfo
object MousePosition extends App {
Line 778 ⟶ 781:
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).
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)
'X and Y are in "twips" -- 15 twips per pixel
Line 785 ⟶ 792:
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.
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.
<lang vb>Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Line 806 ⟶ 814:
=={{header|XPL0}}==
GetMousePosition(0) = X coordinate; 1 = Y coordinate.
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.
For modes $F..$12 the coordinates are the same as the pixels.
VESA graphic modes are (usually) 639x479 regardless of the resolution.
Line 813 ⟶ 821:
character cursor position.
 
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
code because the version of XPL0 used with these Rosetta Code examples
does not make Windows applications (however see "Simple windowed application").
Anonymous user