Jump to content
Sign in to follow this  
Rawox

MouseGetPos part of screen

Recommended Posts

Rawox

Hey..

I need to know of the cursor is in an apart piece of the screen. For example somewhere between 100 pxl, 100pxl and 200 pxl, 200pxl.

A piece of 100 pxls height and 100 pxls width as you can see.

Anyone?

Rawox

Share this post


Link to post
Share on other sites
Melba23

Rawox,

You have the answer in your title - look at MouseGetPos in the Help file. Then use some If or Switch statements.

M23

P.S. You might like to look at Opt(MouseCoordMode) as well. ;-)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Rawox

I already tried these things. Isn't there an option like PixelSearch

left left coordinate of rectangle. 
top top coordinate of rectangle. 
right right coordinate of rectangle. 
bottom bottom coordinate of rectangle.

If not, can someone please show an example??

Share this post


Link to post
Share on other sites
somdcomputerguy

If not, can someone please show an example??

Function MouseGetPos

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
Rawox

Snowmaker. That doesn't make sense to me!

How can I check for the cursor in a given rectangle?

I know I can do it with MouseGetPos, why don't you guys just show an example if it isn't that hard?

Share this post


Link to post
Share on other sites
somdcomputerguy

Define top/left and bottom/right, or all four corners maybe, use mousegetpos to see if it's 'in there'. That's how I would tackle the situation first. It's maybe the wrong way to do it, but that's where I'd start anyway. Write some code, post it and any problems, I'm sure you'll get some help from others here.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
Melba23

Rawox,

I know I can do it with MouseGetPos, why don't you guys just show an example if it isn't that hard?

So what have you tried yourself? Just shouting at us will not get your code written for you!

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Rawox

$WinPos = WinGetPos ( "Smaryl" )
    $MousePos = MouseGetPos ( )
    $Top = @DesktopHeight/2-35-$height/2
    $Left = 0
    $Right = $width-5
    $Bottom = @DesktopHeight/2-35+$height/2
    If $MousePos[0] = $Top And $MousePos[1] = $Left Then
        
    EndIf

But this just checks 1 pixel, doesn't it?

Share this post


Link to post
Share on other sites
Melba23

Rawox,

Try thinking logically.

You want to know if your cursor is between (100, 100) and (200, 200). What do you think the If or Switch statements might look like? In your code above I see no sign of either 100 or 200 - so how do you expect to find out if your cursor is within those limits?

How about trying to code something based on this:

; Get mouse position
$aM_Pos = MouseGetPos()
Switch $aM_Pos[0]
    ; Is mouse within X coords?
    Case 100 To 200
        Switch $aM_Pos[1]
            ; Is mouse within Y coords?
            Case 100 To 200
                ; Mouse in the box
            ; If not
            Case Else
                ; Mouse not in the box
        EndSwitch
    ; If not
    Case Else
        ; Not in the box
EndSwitch

Over to you. :-)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Rawox

Thanks Melba!

I tried this, I don't really understand your switch statements but with your help I thought this would work, but why doesn't it?

$MousePos = MouseGetPos ( )

    For $MousePos[0] = 100 To 200
        For $MousePos[1] = 100 To 200
            MsgBox ( 0, "lol", "lol" )
        Next
    Next

It just always displays the msgbox :)

Share this post


Link to post
Share on other sites
Thornhunt

maybe

if mousepos[0] < *** and mousepos[0] > *** and mousepos[1] < *** and mousepos[1] > *** then

...

ect ect.. maybee ? have you tried that.. might work :)


Budweiser + room = warm beerwarm beer + fridge = too long!warm beer + CO2 fire extinguisher = Perfect![quote]Protect the easly offended ... BAN EVERYTHING[/quote]^^ hmm works for me :D

Share this post


Link to post
Share on other sites
Yashied

maybe

if mousepos[0] < *** and mousepos[0] > *** and mousepos[1] < *** and mousepos[1] > *** then

...

ect ect.. maybee ? have you tried that.. might work :)

if (mousepos[0] < ***) and (mousepos[0] > ***) and (mousepos[1] < ***) and (mousepos[1] > ***) then

Share this post


Link to post
Share on other sites
Thornhunt

if (mousepos[0] < ***) and (mousepos[0] > ***) and (mousepos[1] < ***) and (mousepos[1] > ***) then

hhehehe thats what i meant :):)

Budweiser + room = warm beerwarm beer + fridge = too long!warm beer + CO2 fire extinguisher = Perfect![quote]Protect the easly offended ... BAN EVERYTHING[/quote]^^ hmm works for me :D

Share this post


Link to post
Share on other sites
Rawox

Thanks it worked!!

Share this post


Link to post
Share on other sites
Melba23

Rawox,

I thought this would work, but why doesn't it?

$MousePos = MouseGetPos ( )

For $MousePos[0] = 100 To 200
    For $MousePos[1] = 100 To 200
        MsgBox ( 0, "lol", "lol" )
    Next
Next
You are joking, of course? For...Next is for counting through a loop:
For $i = 1 to 4
    ConsoleWrite($i & @CRLF)
Next

will give you

1
2
3
4

So your code above would give you you two loops which would display a total of 10000 MsgBox's....hardly surprising that:

It just always displays the msgbox

If you want to become proficient at AutoIt coding, you must try and understand how the simple, often-used functions work. I commented the Switch example above to try and point you in the right direction. Just play with the examples in the Help file until you see how and why they do what they do. I know it is less fun than coding your own stuff, but understanding the basics of the commands you use will increase your ability to code correctly - and reduce the frustration of not understanding why your code does not work as you wish. It would be time well spent, believe me.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×