Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

WinControlSetEvent UDF


  • Please log in to reply
3 replies to this topic

#1 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 01 June 2009 - 05:26 PM

This UDF allows to catch an event (pressed/released) from specific window's control.

Header:

Plain Text         
; #FUNCTION# ==================================================================================================== ; Name...........: _WinControlSetEvent ; Description ...: Sets an event for Window control. ; Syntax.........: Func(hWindow, nCtrlID, $sCallOnHoldFunc [, $sOnHoldParams [, $sCallOnReleaseFunc [, $sOnReleaseParams]]]) ; ; Parameters ....: $hWindow         - Parent window handle (or class name) that have the control to set event for. ;                 $nCtrlID          - CtrlID (or control text) of the control to set the event for. ;                 $sCallOnHoldFunc  - Function name to call when event is fired (control is pressed *down*). ;                 $sOnHoldParams      - [Optional] Extra parameters to pass to the called function ($sCallOnHoldFunc). ;                 $sCallOnReleaseFunc - [Optional] Function to call when event is fired (control is released after pressing down). ;                 $sOnReleaseParams   - [Optional] Extra parameters to pass to the called function ($sCallOnReleaseFunc). ; ; Return values .: Always return 1. ; ; Author ........: G.Sandler (a.k.a MrCreatoR). ; Modified.......: 22.01.2009, 20:00 ; ; Remarks .......: 1) This UDF includes OnAutoItExit function to release the callback/hooks resources. ;                 2) Blocking of $sCallOnHoldFunc/$sCallOnReleaseFunc function by window messages with commands ;                    such as "Msgbox()" can lead to unexpected behavior, the return to the system should be as fast as possible! ; ; Related .......: _WinCtrlEvents_Handler, _ControlGetHoveredID, _WinGetHoveredHandle, _OnAutoItExit ; Link ..........; ; Example .......; Yes ; ====================================================================================================


Example:

AutoIt         
#include <WinControlSetEvent.au3> ;============== Calc Demo ============== ;In this example we use the main loop to avoid blocking of mouse processing from inside CalcGetResult_Proc() function. HotKeySet("^q", "_Quit") $iGetCalcResults = False Run("Calc.exe") For $i = 1 To 9     _WinControlSetEvent("[CLASS:SciCalc]", $i, "", "", "CalcGetResult_Proc", "'" & $i & "' Button has been pressed") Next _WinControlSetEvent("[CLASS:SciCalc]", "=", "", "", "CalcGetResult_Proc", "'=' Button has been pressed") _WinControlSetEvent("[CLASS:SciCalc]", "/", "", "", "CalcGetResult_Proc", "'/' Button has been pressed") _WinControlSetEvent("[CLASS:SciCalc]", "*", "", "", "CalcGetResult_Proc", "'*' Button has been pressed") _WinControlSetEvent("[CLASS:SciCalc]", "-", "", "", "CalcGetResult_Proc", "'-' Button has been pressed") _WinControlSetEvent("[CLASS:SciCalc]", "+", "", "", "CalcGetResult_Proc", "'+' Button has been pressed") _WinControlSetEvent("[CLASS:SciCalc]", "Button28", "", "", "CalcGetResult_Proc", "'X' Button has been pressed") While 1     Sleep(10)         If $iGetCalcResults <> False Then         $iParam = $iGetCalcResults         $iGetCalcResults = False                 If $iParam = 168 Then Exit ;Calc closed                 $sCtrl_Data = ControlGetText("[CLASS:SciCalc]", "", $iParam)                 If $sCtrl_Data = "=" Then             Local $sResult = StringStripWS(ControlGetText("[CLASS:SciCalc]", "", "Edit1"), 3)             If StringRight($sResult, 1) = "," Then $sResult = StringTrimRight($sResult, 1)                     ToolTip("The result has been calculated: " & $sResult, Default, Default, "Calc Info", 1, 5)         ElseIf $sCtrl_Data <> "" Then             ToolTip("Calc Button Pressed: " & $sCtrl_Data, Default, Default, "Calc Info", 1, 5)         EndIf     EndIf WEnd ;Warning: blocking of this function by window messages with commands such as "Msgbox()" can lead to unexpected behavior, ;the return to the system should be as fast as possible !!! Func CalcGetResult_Proc($sParams, $hWnd, $nCtrlID)     ConsoleWrite("Passed params: " & $sParams & @CRLF)         $iGetCalcResults = $nCtrlID EndFunc Func _Quit()     Exit EndFunc


Attached File  WinControlSetEvent.zip   2.78KB   544 downloads

Edited by MrCreatoR, 01 June 2009 - 05:27 PM.

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team








#2 wraithdu

wraithdu

    this noise inside my head

  • MVPs
  • 2,413 posts

Posted 01 June 2009 - 07:59 PM

Nice UDF.

I came up with another way to trigger actions while not blocking the message queue and not using the main loop. I used it for my MD5 gui script. The basic idea is to create a hidden GUI with a dummy control (GuiCtrlCreateDummy()), then when you want to do something, you send it a message with GuiCtrlSendToDummy() and pass it some identifying data. That data can be read in the dummy's OnEvent function with GuiCtrlRead() to determine what it needs to do. Sending the event is the last thing in your message loop function before returning to the main script. This approach worked great for me, since I obviously didn't want to be hashing huge files and have the script stuck in the message loop.

#3 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 01 June 2009 - 08:58 PM

Nice UDF.

Thanks.

I came up with another way to trigger actions while not blocking the message queue and not using the main loop. I used it for my MD5 gui script. The basic idea is to create a hidden GUI with a dummy control (GuiCtrlCreateDummy()), then when you want to do something, you send it a message with GuiCtrlSendToDummy() and pass it some identifying data. That data can be read in the dummy's OnEvent function with GuiCtrlRead() to determine what it needs to do. Sending the event is the last thing in your message loop function before returning to the main script. This approach worked great for me, since I obviously didn't want to be hashing huge files and have the script stuck in the message loop.

But it's required OnEvent mode enabled, not all of us (and not for all our scripts) using this mode.
And in a matter of fact, this can be done seperately by you (as user), the event function just give you the needed trigger, what will happend next it's up to you.

P.S
To avoid the main loop inolving, we can use Adlib*:

Func _Event_Trigger_Proc($sParams, $hWnd, $nCtrlID)     ConsoleWrite("Passed params: " & $sParams & @CRLF)         $iGetCalcResults = $nCtrlID     AdlibEnable("_Event_Main_Proc", 1) EndFunc Func _Event_Main_Proc()     AdlibDisable()     ;Here we can do whatever we need when event is triggered EndFunc

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#4 joseLB

joseLB

    Polymath

  • Active Members
  • PipPipPipPip
  • 246 posts

Posted 09 November 2009 - 03:23 PM

Thanks Mr.Creator,
I just downloaded it, didn't test yet, bu by sure it would solve many problems I had .
Jose

Edited by joseLB, 09 November 2009 - 03:30 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users