Jump to content

Do loop until mouse button release


 Share

Recommended Posts

Hello everyone,

 

I am messing with a Do loop, and i wana know, how can i set it to finish the loop, when i release Mosue button. (Was started with mouse button press)

Used _IsPressed to start

Any idea how to tell it to the program something like this:

Do
    ToolTip("Still pressing", 0, 0)
    Sleep(100)
Until ; Here i need to make it stop, when i release the mouse button

 

Tricky

Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

Link to comment
Share on other sites

  • Moderators

Trickydeath,

_IsPressed.

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

I tried that one as well, but i bet i made mistake. _IsPressed is not for pressing the button only?

I see now, i am so lame....

Until _IsPressed("01", $hDLL) = False

 

Thank You, :)

Edited by TrickyDeath

Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

Link to comment
Share on other sites

  • Moderators

TLM,

I would strongly suggest a Sleep(10) inside that very tight loop to save the CPU.

And when you post code please use Code tags - see here how to do it.  Then you get syntax colouring as you can see above now I have added the tags.

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

How this:

#include <Misc.au3>

While 1
    If _IsPressed(1) Then ;Check press of left mouse
        While _IsPressed(1); while is working when hold leftmouse
            ToolTip("LeftMouse Down")
        WEnd
        ToolTip("LeftMouse UP")
    EndIf
    sleep(10)
WEnd

Well i did different, and about your code, it run the second while loop for 1 "ms" cause the button is pressed (argument succesful), the tooltip is displaied "ToolTip("LeftMouse Down")" and instatnly the second tooltip pop up.Ok, i checked your code and also work, my bad sry. Will test that way as well.

For my logic, Do loop was better idea, since i have to hold down the button for a while and the code have to run over and over till the mouse button is down. When i release it, it have to stop. So M23 helped me out, cause seams like i was too tired and did not think i can put "= False" (_IsPressed("01", $hDLL) = False). Funy part is with different way i did try like that, but not with _IsPressed... :(

With _IsPressed i had to notice if i press AltGR and the sleep is too long, it pressing multiple button cause it is groupped button. Still did not identify few button, and unfortunately, not working that function with my media buttons on my keyboard, but still cool stuff.

Edited by TrickyDeath
Tested TLM's code

Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

Link to comment
Share on other sites

Well i did different, and about your code, it run the second while loop for 1 "ms" cause the button is pressed (argument succesful), the tooltip is displaied "ToolTip("LeftMouse Down")" and instatnly the second tooltip pop up.Ok, i checked your code and also work, my bad sry. Will test that way as well.

For my logic, Do loop was better idea, since i have to hold down the button for a while and the code have to run over and over till the mouse button is down. When i release it, it have to stop. So M23 helped me out, cause seams like i was too tired and did not think i can put "= False" (_IsPressed("01", $hDLL) = False). Funy part is with different way i did try like that, but not with _IsPressed... :(

With _IsPressed i had to notice if i press AltGR and the sleep is too long, it pressing multiple button cause it is groupped button. Still did not identify few button, and unfortunately, not working that function with my media buttons on my keyboard, but still cool stuff.

Ok use this it is better than all

#include <APISysConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

; Create GUI
Global $GUI = GUICreate('Test', 1, 1)

Local $tRID = DllStructCreate($tagRAWINPUTDEVICE)
DllStructSetData($tRID, 'UsagePage', 0x01) ; Generic Desktop Controls
DllStructSetData($tRID, 'Usage', 0x02) ; Mouse
DllStructSetData($tRID, 'Flags', $RIDEV_INPUTSINK)
DllStructSetData($tRID, 'hTarget', $GUI)
_WinAPI_RegisterRawInputDevices($tRID)

GUIRegisterMsg($WM_INPUT, 'WM_INPUT')

GUISetState(@SW_HIDE)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_INPUT($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam
    Switch $hWnd
        Case $GUI
            Local $tRIM = DllStructCreate($tagRAWINPUTMOUSE)
            If _WinAPI_GetRawInputData($lParam, $tRIM, DllStructGetSize($tRIM), $RID_INPUT) Then
                Local $iFlags = DllStructGetData($tRIM, 'Flags')
                Select
                    Case BitAND($iFlags, $MOUSE_ATTRIBUTES_CHANGED)
                        ; You need to query the mouse attributes and update bitmap...
                    Case Else

                EndSelect
                $iFlags = DllStructGetData($tRIM, 'ButtonFlags')
                If BitAND($iFlags, BitOR($RI_MOUSE_MIDDLE_BUTTON_DOWN, $RI_MOUSE_MIDDLE_BUTTON_UP, $RI_MOUSE_LEFT_BUTTON_DOWN, $RI_MOUSE_LEFT_BUTTON_UP, $RI_MOUSE_RIGHT_BUTTON_DOWN, $RI_MOUSE_RIGHT_BUTTON_UP)) Then

                    Select
                        Case BitAND($iFlags, $RI_MOUSE_LEFT_BUTTON_DOWN)
                            If Not _CheckOtheBtnPress(1) Then
                                ToolTip("Mouse Left btn down")
                            EndIf
                        Case BitAND($iFlags, $RI_MOUSE_LEFT_BUTTON_UP)
                            If Not _CheckOtheBtnPress(1) Then
                                ToolTip("Mouse Left btn up")
                            EndIf
                        Case BitAND($iFlags, $RI_MOUSE_RIGHT_BUTTON_DOWN)
                            If Not _CheckOtheBtnPress(2) Then
                                ToolTip("Mouse Right btn down")
                            EndIf
                        Case BitAND($iFlags, $RI_MOUSE_RIGHT_BUTTON_UP)
                            If Not _CheckOtheBtnPress(2) Then
                                ToolTip("Mouse Right btn up")
                            EndIf
                    EndSelect
                EndIf
            EndIf
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_INPUT


Func _CheckOtheBtnPress($keytoIGNORE)
    For $C = 1 To 222 Step 1
        If $C = $keytoIGNORE Then ContinueLoop
        If _IsPressed(Hex($C, 2)) Then Return 1
    Next
    Return 0
EndFunc

 

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