Displaying Mouse Coordinates
Posted: Wed Jun 10, 2009 10:14 pm
I have had need for a quick program to display the coordinates of the mouse cursor for writing macro programs.
I came up with this little program. Unfortunately it uses Windows API calls. And I do not have Mac or Linux systems to test for the other two op systems anyway.
So far it has worked very well.
Has made life easier for making macros that is for sure.
Here is a nifty little icon file for it if you want to make an .exe file and have to use from the desktop.
http://www.yasdc.com/downloads/Where.ico
And for those who want it pre-compiled
http://www.yasdc.com/downloads/MouseLoc.exe
=====================
By the way there is a typo in the program. But if I correct the typo, the program crashes (will not compile/run). If I leave the typo in it works fine. See if you can spot the typo and then see if you can explain the behavior of the program.
(FIXED NO LONGER IN ABOVE CODE)
=====================
Slyvnr
I came up with this little program. Unfortunately it uses Windows API calls. And I do not have Mac or Linux systems to test for the other two op systems anyway.
Code: Select all
;-----------------------------------------------------
;
; MouseLoc.pb
; June 10 2009
; Version 1.1
;
; V 1.1 06/10/2009
; Added lines to make window sticky to stay on top
;
; V 1.0 06/09/2009
; simply tell us where the mouse cursor is on the
; desktop
;-----------------------------------------------------
;Declare structures
Structure tagPOINT
x.l
y.l
EndStructure
Global POINT.tagPOINT
;--------------------
;Main program
;--------------------
; Get the resolution of the desktop
ExamineDesktops()
DT_Width=DesktopWidth(0)
DT_Height=DesktopHeight(0)
; Figure out where to place window to display mouse coordinates
Win_Width=90
Win_Height=20
Pos_x=DT_Width-Win_Width-22
Pos_y=DT_Height-Win_Height-52
; create window in which we will display the mouse coordinates
If OpenWindow(0, Pos_x, Pos_y, Win_Width, Win_Height, "Mouse Loc", #PB_Window_SystemMenu )
txt_titlex=TextGadget(#PB_Any,5,5,10,20,"X:")
txt_MouseX=TextGadget(#PB_Any,20,5,40,20,"0.00")
txt_titley=TextGadget(#PB_Any,60,5,10,20,"Y:")
txt_MouseY=TextGadget(#PB_Any,75,5,40,20,"0.00")
EndIf
;Keep window on top of all other windows
StickyWindow(0,1)
; setup a variable to check for program close
CLOSEME=0
Repeat
;keep window on top
; check to see if window X has been pressed
e=WindowEvent()
If e=#PB_Event_CloseWindow
CLOSEME=1 ; if window X has been pressed set variable to end loop
EndIf
; Get Cursor Position
GetCursorPos_(@POINT)
MouseX$=Str(POINT\x)
MouseY$=Str(POINT\y)
;Update Cursor Position in Output window
SetGadgetText(txt_MouseX,MouseX$)
SetGadgetText(txt_MouseY,MouseY$)
; ;smoother update of mouse coordinates and also release CPU to other processes
;basically helps prevents system resource hogging
Sleep_(70)
Until CLOSEME ; if CLOSEME then lets exit and end the program
End
Has made life easier for making macros that is for sure.
Here is a nifty little icon file for it if you want to make an .exe file and have to use from the desktop.
http://www.yasdc.com/downloads/Where.ico
And for those who want it pre-compiled
http://www.yasdc.com/downloads/MouseLoc.exe
=====================
By the way there is a typo in the program. But if I correct the typo, the program crashes (will not compile/run). If I leave the typo in it works fine. See if you can spot the typo and then see if you can explain the behavior of the program.
(FIXED NO LONGER IN ABOVE CODE)
=====================
Slyvnr