Sign in to follow this  
Followers 0
mattschinkel

Detect if button has been pressed on software?

11 posts in this topic

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.

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

Try this:

#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_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Thanks MrCreatoR, Your script works great!

Share this post


Link to post
Share on other sites

#7 ·  Posted (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

post-81487-0-67435900-1424709457_thumb.g

Edited by antonioj84

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

Smoke_N and  Bert thanks, I  will start a new thread. I am stumped. I thought it would have been pretty straight forward coding

Share this post


Link to post
Share on other sites

please refer to this links (solved)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0