Jump to content

Can't get mouse click


nmontec
 Share

Recommended Posts

Hello All,

I've got the following function:

Func StoreCoordinate()
    WinActivate("PPP")
    WinWaitActive("PPP")
    while 1
        $msg=GUIGetMsg ()
        if $msg<>0 Then
                if $msg==$GUI_EVENT_PRIMARYDOWN Then
                    $Stella=MouseGetPos()
                    ConsoleWrite($Stella[0]& " " & $Stella[1] & chr(13))
                    ExitLoop
                EndIf
        EndIf
    WEnd
        Return $Stella
EndFunc

This function never ends despite I clicked with the mouse many times. Do you know why the loop never ends?

Thanks for the help

Nicola

Link to comment
Share on other sites

  • Moderators

nmontec,

This function returns for me every time:

Func StoreCoordinate()
    WinActivate("PPP")
    WinWaitActive("PPP")

    While 1

        If GUIGetMsg() = $GUI_EVENT_PRIMARYDOWN Then
            $Stella = MouseGetPos()
            ConsoleWrite($Stella[0] & " " & $Stella[1] & @CRLF)
            Return $Stella
        EndIf

    WEnd

EndFunc   ;==>StoreCoordinate

I hope it works for you too. :D

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

This function returns for me every time:

No it does not work also in the way you rewrote it. :D

This is the full code I tried:

#include <GUIConstantsEx.au3>

Func StoreCoordinate()
    WinActivate("PHD")
    WinWaitActive("PHD")

    While 1

        If GUIGetMsg() = $GUI_EVENT_PRIMARYDOWN Then
            $Stella = MouseGetPos()
            ConsoleWrite($Stella[0] & " " & $Stella[1] & @CRLF)
            Return $Stella
        EndIf

    WEnd

EndFunc

AutoItSetOption("WinTitleMatchMode",2)
AutoItSetOption ( "MouseCoordMode" , 0)
$Stella=StoreCoordinate()
Link to comment
Share on other sites

  • Moderators

nmontec,

You do realise that you can only click within the "PHD" window? :D

As before, this code works for me - please try it and see it if works for you when you click within the "PHD" GUI:

#include <GUIConstantsEx.au3>
#include <Array.au3>

$hGUI = GUICreate("PHD", 500, 500)
GUISetState()

Func StoreCoordinate()
    WinActivate("PHD")
    WinWaitActive("PHD")

    While 1

        If GUIGetMsg() = $GUI_EVENT_PRIMARYDOWN Then
            $Stella = MouseGetPos()
            ConsoleWrite($Stella[0] & " " & $Stella[1] & @CRLF)
            Return $Stella
        EndIf

    WEnd

EndFunc

AutoItSetOption("WinTitleMatchMode",2)
AutoItSetOption ( "MouseCoordMode" , 0)
$Stella=StoreCoordinate()

_ArrayDisplay($Stella)

The Array stuff is just there to doublecheck the return - you can delete it later. :huggles:

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

You do realise that you can only click within the "PHD" window? :D

Yes, this is the intended purpose of this piece of code. It does not work anywhere within the PHD window or outside of it. :huggles:

Edit: I just tried to print out the GUIGetMsg() and it always returns 0.

I guess this means that it never gets for any reason any event...this is weird. It's my first time to get events, but the code to me seems treally simple that I don't know where I could have mistaken.

Func StoreCoordinate()
    WinActivate("PHD")
    WinWaitActive("PHD")

    While 1
        $msg=GUIGetMsg()
        ConsoleWrite($msg & @CRLF)
        If $msg = $GUI_EVENT_PRIMARYDOWN Then
            $Stella = MouseGetPos()
            ConsoleWrite($Stella[0] & " " & $Stella[1] & @CRLF)
            Return $Stella
        EndIf

    WEnd

EndFunc
Edited by nmontec
Link to comment
Share on other sites

  • Moderators

nmontec,

Are you telling me that the code I posted above does not run when pasted on its own into SciTE? :D

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

nmontec,

Are you telling me that the code I posted above does not run when pasted on its own into SciTE? :D

M23

yes it does work, but what's the difference between my application "PHD" and your window "PHD"?

I don't understand...

PS: I tried also with other windows like firefox, same thing, I don't get the event.

Edited by nmontec
Link to comment
Share on other sites

  • Moderators

nmontec,

On reflection, I believe the event is only fired when you are within your own GUI. So as soon as you activate another - which of course you do by clicking on it :D - you are immediately in another GUI and the event does not fire.

So let use use _IsPressed to solve this. We can easily convert the coordinates fron absolute screen to the PHP client area by using the WinAPI call.

Please try this code:

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WinAPI.au3>

$hGUI = GUICreate("PHP", 500, 500)

GUISetState()

Func StoreCoordinate()

    Local $tPoint = DllStructCreate("int X;int Y")

    $dll = DllOpen("user32.dll")

    While 1

        If _Ispressed("01", $dll) = 1 Then
            $Stella = MouseGetPos()
            ConsoleWrite("Screen coords: " & $Stella[0] & " - " & $Stella[1] & @CRLF)
            ExitLoop
        EndIf

    WEnd

    DllClose($dll)

    WinActivate("PHP")
    WinWaitActive("PHP")
    $hWnd = WinGetHandle("PHP")

    DllStructSetData($tPoint, "X", $Stella[0])
    DllStructSetData($tPoint, "Y", $Stella[1])

    _WinAPI_ScreenToClient($hWnd, $tPoint)

    $Stella[0] = DllStructGetData($tPoint, "X")
    $Stella[1] = DllStructGetData($tPoint, "Y")

    ConsoleWrite("PHP coords: " & $Stella[0] & " - " & $Stella[1] & @CRLF)

    Return $Stella

EndFunc

AutoItSetOption("WinTitleMatchMode",2)
;AutoItSetOption ( "MouseCoordMode" , 0)
$Stella=StoreCoordinate()

Now you should see 2 rows of info in the SciTE console. The first line is the absolute screen coords, the second the coords relative to the client area of the PHP window.

Does this work for you? And, more importantly, does it work when you use your own "PHP" window?

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

Does this work for you? And, more importantly, does it work when you use your own "PHP" window

Yes, it does work and it works with my window!

Now, this is nice, but I don't understand how you reached this, I never use the WinAPI so I don't know how to use it. Can you point me out to some documentation regarding this API? I'm also relatively new to Windows... :D

Link to comment
Share on other sites

  • Moderators

nmontec,

Mat is quite correct in pointing you towards the MSDN - this is the "bible" which tells you in great detail (practically!?!) everything you could ever want to know about the Windows API.

However, as a mere hobbyist coder, I can get very easily lost in there and as a beginner you would need more breadcrumbs that Hansel and Gretel to get out again! : What I recommend is a look through the WInAPI section of the Help file - you find it under the bottom item in the menu <User Defined Functions reference - WInAPI Management>. There are lots of interesting functions there which are easy to use in AutoIt and which can help solve some tricky problems - like this one!

I often bemoan the fact that the Help file appears to be ignored by many AutoIt users - wait until they try some other languages and they will realise how lucky we are to have such a resource. A little time spent perusing the Help file will repay itself a thousand times over when a little light goes on - "Ah, I remember reading something about that.....! :D ".

So, I would recommend leaving MSDN alone at the moment - stick with the AutoIt specific commands in the Help file until you are a bit more comfortable with teh API. And of course you know where we are if you need a bit of advice. :huggles:

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