mattschinkel Posted January 21, 2009 Posted January 21, 2009 Hi, Is there any way I can detect if a button on a piece of software has been pressed? I need to change what a button on some software does by running my own function when pressed. For example. If I have the windows "calculator" program open. Whenever the = sign is pressed, I want a message box to pop up saying "the result has been calculated" Thanks, Matt.
Moderators SmOke_N Posted January 21, 2009 Moderators Posted January 21, 2009 Hi, Is there any way I can detect if a button on a piece of software has been pressed? I need to change what a button on some software does by running my own function when pressed.For example. If I have the windows "calculator" program open. Whenever the = sign is pressed, I want a message box to pop up saying "the result has been calculated"Thanks,Matt.SetWindowsHookEx + CallNextHook Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
MrCreatoR Posted January 21, 2009 Posted January 21, 2009 Try this: expandcollapse popup#include <Misc.au3> #include <WinAPI.au3> ; Global $hUser32_Dll = DllOpen("User32.dll") HotKeySet("^e", "_Quit") While 1 If _IsPressed("01", $hUser32_Dll) Then ;Waiting untill the button is released While _IsPressed("01", $hUser32_Dll) Sleep(10) WEnd $hWindow = _WinGetHoveredHandle() $iCtrlID = _ControlGetHoveredID() $sWinClass = _WinAPI_GetClassName($hWindow) $sCtrlData = ControlGetText($hWindow, "", $iCtrlID) If $sWinClass = "SciCalc" And $iCtrlID <> 0 And $sCtrlData = "=" Then $sResult = Number(ControlGetText($hWindow, "", "Edit1")) ToolTip("The result has been calculated: " & $sResult, Default, Default, "Calc Info", 1, 5) Else ToolTip("") EndIf EndIf Sleep(10) WEnd Func _ControlGetHoveredID() Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1) Local $hRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) $hRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hRet[0]) If $hRet[0] < 0 Then $hRet[0] = 0 Opt("MouseCoordMode", $iOld_Opt_MCM) Return $hRet[0] EndFunc Func _WinGetHoveredHandle() Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1) Local $aRet = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1)) Opt("MouseCoordMode", $iOld_Opt_MCM) $aRet = DllCall("User32.dll", "hwnd", "GetAncestor", "hwnd", $aRet[0], "uint", 2) ;$GA_ROOT Return HWnd($aRet[0]) EndFunc Func _Quit() DllClose($hUser32_Dll) Exit EndFunc Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler 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 ProgramUDFs: 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 UDF 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 Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
Manjish Posted January 21, 2009 Posted January 21, 2009 u can do a GuiCtrlRead on the button. Use AutoIt Window Info tool to get the necessary info. Just check if the button is higghlighted with a black box when u drag the finder cursor on it. If it does, then that means that the ctrl is recognized as a button by autoit. N u can then easily read whether the button is pressed. Cheers. [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
MrCreatoR Posted January 21, 2009 Posted January 21, 2009 u can do a GuiCtrlRead on the button. Use AutoIt Window Info tool to get the necessary info. Just check if the button is higghlighted with a black box when u drag the finder cursor on it. If it does, then that means that the ctrl is recognized as a button by autoit. N u can then easily read whether the button is pressed.Cheers.GUICtrlRead will not work on external applications Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler 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 ProgramUDFs: 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 UDF 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 Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
mattschinkel Posted January 21, 2009 Author Posted January 21, 2009 Thanks MrCreatoR, Your script works great!
antonioj84 Posted February 23, 2015 Posted February 23, 2015 (edited) I am trying to run your code on this application can you point me , why it's not working , I just need when click "=" a message to pop Edited February 23, 2015 by antonioj84
Moderators SmOke_N Posted February 23, 2015 Moderators Posted February 23, 2015 (edited) Things have probably changed in 6 years! Please start your own help thread with a reference link to the code that isn't working. In your support thread, be very specific on what you've done to debug what isn't working. Edit: A little hint, the "class" is different, so you'll have to change that. Edited February 23, 2015 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Bert Posted February 23, 2015 Posted February 23, 2015 You know this thread is 6 years old and the poster is most likely no longer here? The Vollatran project My blog: http://www.vollysinterestingshit.com/
antonioj84 Posted February 23, 2015 Posted February 23, 2015 Smoke_N and Bert thanks, I will start a new thread. I am stumped. I thought it would have been pretty straight forward coding
Recommended Posts