AlainB Posted April 19, 2011 Share Posted April 19, 2011 Hi, When you click on a button, the action will start only when you release the button, not when you press on it. On the script below, the buttons are used more like a toggle switch. Is there a way to make the action start when you press the button and stop when you release it, more like a momentary switch? Thanks! Alain expandcollapse popup#include <GUIConstantsEx.au3> Dim $Delay=20 $Dll = DllOpen("inpout32.dll") DllClose("inpout32.dll") $Form = GUICreate("",275,150) $Button1 = GUICtrlCreatebutton("CCW",55,50,75,50) $Button2 = GUICtrlCreatebutton("CW",150,50,75,50) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Switch $msg Case $Button1 $Label = " Running CCW" $a=192 $b=128 SendSteps() Case $Button2 $Label = " Running CW" $a=64 $b=0 SendSteps() Case $GUI_EVENT_CLOSE DllCall( $Dll, "int", "Out32", "int", 0x378, "int", 0) Exit EndSwitch WEnd func SendSteps() GUICtrlCreatelabel($Label,110,120,75,17) while 1 DllCall( $Dll, "int", "Out32", "int", 0x378, "int", $a) sleep($Delay) DllCall( $Dll, "int", "Out32", "int", 0x378, "int", $b) sleep($Delay) $msg=GUIGetMsg() if $msg=$Button2 or $msg=$Button1 Then GUICtrlCreatelabel(" Stopped!",110,120,75,17) ExitLoop EndIf WEnd EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 19, 2011 Moderators Share Posted April 19, 2011 AlainB, Wlcome to the AutoIt forum. Her is one way to do what you want: #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $hButton = GUICtrlCreateButton("Press", 10, 10, 80, 30) $hLabel = GUICtrlCreateLabel("Not Pressed", 10, 50, 200, 20) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; Look at where the cursor is at this moment $aCInfo = GUIGetCursorInfo() ; If the button is pressed and we are over the button If $aCInfo[2] And $aCInfo[4] = $hButton Then If GUICtrlRead($hLabel) <> "Pressed" Then GUICtrlSetData($hLabel, "Pressed") EndIf Else If GUICtrlRead($hLabel) <> "Not Pressed" Then GUICtrlSetData($hLabel, "Not Pressed") EndIf EndIf WEnd You need the extra checks on the button text to prevent flashing. Does that help? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
UEZ Posted April 19, 2011 Share Posted April 19, 2011 (edited) Here my version: expandcollapse popup#include <GUIConstantsEx.au3> #include <Misc.au3> Opt("GUIOnEventMode", 1) Dim $Delay=20 $Form = GUICreate("",275,150) $Button1 = GUICtrlCreatebutton("CCW",55,50,75,50) $Button2 = GUICtrlCreatebutton("CW",150,50,75,50) GUISetState(@SW_SHOW) $stop = False GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Start") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $dll = DllOpen("user32.dll") While Sleep(10000) WEnd Func Start() While Sleep(10) * _IsPressed("01", $dll) $aM = GUIGetCursorInfo() If $aM[4] <> $Button1 Then ExitLoop Prg1() WEnd EndFunc Func Prg1() Local Static $i = 0 $i += 1 ConsoleWrite($i & @CRLF) EndFunc Func _Exit() DllClose($dll) Exit EndFunc While you press the CCW button it will write to console. Br, UEZ Edit: made some modifications because I didn't like previous version Edited April 19, 2011 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 19, 2011 Moderators Share Posted April 19, 2011 UEZ, You did not close the DLL on exit! Shame on you! M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
UEZ Posted April 19, 2011 Share Posted April 19, 2011 @Melba23: UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
AlainB Posted April 19, 2011 Author Share Posted April 19, 2011 (edited) Thanks both for your fast replies. Yes I think that this is what I need. I will have to study the scripts a bit. I read a few times about the console but I dont know what it is and how to use it. Could you explain. By the way, is there something wrong about loading the DLL in the memory and closing it right away as I am doing in my script? Thanks! Edited April 19, 2011 by AlainB Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 20, 2011 Moderators Share Posted April 20, 2011 AlainB, I read a few times about the console but I dont know what it is and how to use it.In its original meaning it referred to the DOS prompt. In this case it refers to the lower pane of the SciTE editor where you get information on how your script is running or the errors that prevent it from running. The ConsoleWrite function places text there - very useful for debugging. Run this line in SciTE: ConsoleWrite(@CRLF & "Can you see me?" & @CRLF & @CRLF) I get the following in my SciTE lower pane (= the console): >"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "M:\Program\Au3 Scripts\fred4.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams +>08:38:04 Starting AutoIt3Wrapper v.2.0.1.34 Environment(Language:0409 Keyboard:00000809 OS:WIN_VISTA/Service Pack 2 CPU:X64 OS:X86) >Running AU3Check (1.54.19.0) from:C:\Program Files\AutoIt3 +>08:38:04 AU3Check ended.rc:0 >Running:(3.3.6.1):C:\Program Files\AutoIt3\autoit3.exe "M:\Program\Au3 Scripts\Test.au3" Can you see me? +>08:38:04 AutoIT3.exe ended.rc:0 >Exit code: 0 Time: 2.793 You can see how the required text has appeared among the normal info lines. By the way, is there something wrong about loading the DLL in the memory and closing it right away as I am doing in my script?Yes, you might as well not bother opening it in the first place. All clear? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AlainB Posted April 20, 2011 Author Share Posted April 20, 2011 (edited) I was not aware of this function in SciTE. Very convenient. For the readers that don't know, the console can be accessed under the tab VIEW and OUTPUT or by pressing F8. TOOLS and GO or F5 will run the script. It is also very convenient. Alain Edited April 20, 2011 by AlainB Link to comment Share on other sites More sharing options...
monoscout999 Posted April 20, 2011 Share Posted April 20, 2011 (edited) This is simple use GUIGetCursorInfo() i don´t read the whole thread i only respond for the first question... :/ expandcollapse popup#include <GUIConstantsEx.au3> Dim $Delay = 20 $Dll = DllOpen("inpout32.dll") DllClose("inpout32.dll") Global $label, $a, $b, $labelstop = " Stopped!" $Form = GUICreate("", 275, 150) $Button1 = GUICtrlCreateButton("CCW", 55, 50, 75, 50) $Button2 = GUICtrlCreateButton("CW", 150, 50, 75, 50) $label1 = GUICtrlCreateLabel("", 110, 120, 75, 17) GUISetState(@SW_SHOW) While 1 $aMouse = GUIGetCursorInfo() if @error then continueloop $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE DllCall($Dll, "int", "Out32", "int", 0x378, "int", 0) Exit EndSwitch Select case $aMouse[2] = 1 If $aMouse[4] = $Button1 Then $label = " Running CCW" $a = 192 $b = 128 GUICtrlsetdata($label1, $label) do sendsteps() until $aMouse[2] = 1 EndIf If $aMouse[4] = $Button2 Then $label = " Running CW" $a = 64 $b = 0 GUICtrlsetdata($label1, $label) do sendsteps() until $aMouse[2] = 1 EndIf case $aMouse[2] = 0 If Guictrlread($label1) = $label then GUICtrlsetdata($label1, $labelstop) Endif Endselect WEnd Func SendSteps() DllCall($Dll, "int", "Out32", "int", 0x378, "int", $a) Sleep($Delay) DllCall($Dll, "int", "Out32", "int", 0x378, "int", $b) Sleep($Delay) EndFunc ;==>SendSteps To close a dll use dllclose() EDIT: dllclosing at the end of the script.. ;..... allthe script Case $GUI_EVENT_CLOSE DllCall($Dll, "int", "Out32", "int", 0x378, "int", 0) dllclose($dll) Exit ;... more script also ...the GUIGetCursorInfo() Function you can use it on picturebox and else, to make hoverbutton chages.. or picturebuttons, etc, etc.. is an easy way to do Edited April 20, 2011 by monoscout999 Link to comment Share on other sites More sharing options...
AlainB Posted April 20, 2011 Author Share Posted April 20, 2011 Thanks Monoscout999, with the changes you made, my script is working exactely as I wanted it to work. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now