Jump to content

MouseGetPos part of screen


Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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. ;-)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...