Sign in to follow this  
Followers 0
bcgreen24

Clicking Toolbar Button That Is Not Visible

7 posts in this topic

I have a script that allows users to 'click' toolbar buttons with hotkeys (here's a snippet):

$hWnd = ControlGetHandle("Archive Client", "Viewer Control", 106)
$iCmdIDRight = _GUICtrlToolbar_IndexToCommand($hWnd, 21)
$myerror = _GUICtrlToolbar_ClickButton($hWnd, $iCmdIDRight, "", False)

It works well, except when the toolbar buttons are not visible (i.e., when the window is resized, causing the toolbar to be 'cut off'-- see screenshots). I realized that this issue is due to the fact that the toolbar 'ClickButton' command is moving the mouse cursor to the button and 'clicking' on it (you can see the mouse cursor over the buttons briefly after the hotkey is used), and so if the button isn't there to click on, it can't be clicked (if that makes any sense).

So-- long story short: is there a way to send clicks to toolbar buttons (Windows toolbars-- 'ToolbarWindow32') rather than 'physically' clicking on them?

Thanks!

Bryan

post-65791-0-44333400-1309539886_thumb.j

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

theres a function named controlclick() or controlsend() look for them into the help file.

I write this example for you.

local $sleeptime = 2000
ShellExecute("calc.exe")
winwaitactive("[CLASS:CalcFrame]") ; only for test propourses, you can avoid this line.
tooltip("sleeping.")
Sleep($sleeptime*2)
;A way to do it.
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:13]" ) ; press button "C" for cleaning propourses.
tooltip("press button ´C´ for cleaning propourses.")
sleep($sleeptime)
Controlsend("[CLASS:CalcFrame]", "", "[CLASS:#32770]","1{NUMPADADD}2{ENTER}") ; sending keys "1 + 2 ENTER" to control.
tooltip("sending keys `1 + 2 ENTER` to control.")
Sleep($sleeptime)
tooltip("sleeping.")
Sleep($sleeptime*2)
;Another way to do it.
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:13]" ) ; press button "C" for cleaning propourses.
tooltip("press button ´C´ for cleaning propourses.")
sleep($sleeptime)
Controlsend("[CLASS:CalcFrame]", "", "[CLASS:#32770]","1") ; sending 1 to control.
tooltip("sending 1 to control.")
sleep($sleeptime)
Controlsend("[CLASS:CalcFrame]", "", "[CLASS:#32770]","{NUMPADADD}") ; sending + to control.
tooltip("sending + to control.")
sleep($sleeptime)
Controlsend("[CLASS:CalcFrame]", "", "[CLASS:#32770]","2") ; sending 2 to control.
tooltip("sending 2 to control.")
sleep($sleeptime)
Controlsend("[CLASS:CalcFrame]", "", "[CLASS:#32770]","{ENTER}") ; sending ENTER to control.
tooltip("sending ENTER to control.")
Sleep($sleeptime)
tooltip("sleeping.")
Sleep($sleeptime*2)
;And another way to do it.
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:13]" ) ; press button "C" for cleaning propourses.
tooltip("press button ´C´ for cleaning propourses.")
sleep($sleeptime)
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:5]" ) ; press button "1".
tooltip("press button `1`.")
sleep($sleeptime)
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:23]" ) ; press button "+".
tooltip("press button `+`.")
sleep($sleeptime)
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:11]" ) ; press button "2".
tooltip("press button `2`.")
sleep($sleeptime)
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:23]" ) ; press button "=".
tooltip("press button `=`.")
Sleep($sleeptime)
tooltip("Exiting.")
Sleep($sleeptime*3)

A tip, maybe you can send the accelerator key, to the toolbar.

Edited by monoscout999

Share this post


Link to post
Share on other sites

monoscout999, I have been playing with this person's problem, too. Using ControlClick and AutoIt Info Window, I am trying to send a click to the specific button. Being that the buttons are part of a toolbar and do not have their own ID, you must use coordinates within the toolbar. And of course, those coordinates won't work if the button is not visible.

bcgreen24: My best suggestion is to find out if there are any hotkey combinations that perform the "Rotate Image" function. If so, they just send the key combination. If you tell us what program you are using, it would help us to work with it.


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

monoscout999, I have been playing with this person's problem, too. Using ControlClick and AutoIt Info Window, I am trying to send a click to the specific button. Being that the buttons are part of a toolbar and do not have their own ID, you must use coordinates within the toolbar. And of course, those coordinates won't work if the button is not visible.

bcgreen24: My best suggestion is to find out if there are any hotkey combinations that perform the "Rotate Image" function. If so, they just send the key combination. If you tell us what program you are using, it would help us to work with it.

Thank you both for your comments...there are no hotkey combinations that perform the 'Rotate Image' function, which is what led me to write this script in the first place. The program I'm controlling is OnBase ArchiveLink. Users are employing SAP and Archivelink to do data entry, and so the goal is to help them keep their hands on the keyboard at all times, rather than having to switch back and forth between keyboard and mouse.

At this point, the workaround is to make sure their ArchiveLink window is wide enough to show the 'rotate' buttons-- however, since their screen real estate is limited, it would be preferable to be able to size the screen width down (which hides those buttons, of course).

Again, thanks for the input!

Bryan

Share this post


Link to post
Share on other sites

theres a function named controlclick() or controlsend() look for them into the help file.

I write this example for you.

local $sleeptime = 2000
ShellExecute("calc.exe")
winwaitactive("[CLASS:CalcFrame]") ; only for test propourses, you can avoid this line.
tooltip("sleeping.")
Sleep($sleeptime*2)
;A way to do it.
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:13]" ) ; press button "C" for cleaning propourses.
tooltip("press button ´C´ for cleaning propourses.")
sleep($sleeptime)
Controlsend("[CLASS:CalcFrame]", "", "[CLASS:#32770]","1{NUMPADADD}2{ENTER}") ; sending keys "1 + 2 ENTER" to control.
tooltip("sending keys `1 + 2 ENTER` to control.")
Sleep($sleeptime)
tooltip("sleeping.")
Sleep($sleeptime*2)
;Another way to do it.
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:13]" ) ; press button "C" for cleaning propourses.
tooltip("press button ´C´ for cleaning propourses.")
sleep($sleeptime)
Controlsend("[CLASS:CalcFrame]", "", "[CLASS:#32770]","1") ; sending 1 to control.
tooltip("sending 1 to control.")
sleep($sleeptime)
Controlsend("[CLASS:CalcFrame]", "", "[CLASS:#32770]","{NUMPADADD}") ; sending + to control.
tooltip("sending + to control.")
sleep($sleeptime)
Controlsend("[CLASS:CalcFrame]", "", "[CLASS:#32770]","2") ; sending 2 to control.
tooltip("sending 2 to control.")
sleep($sleeptime)
Controlsend("[CLASS:CalcFrame]", "", "[CLASS:#32770]","{ENTER}") ; sending ENTER to control.
tooltip("sending ENTER to control.")
Sleep($sleeptime)
tooltip("sleeping.")
Sleep($sleeptime*2)
;And another way to do it.
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:13]" ) ; press button "C" for cleaning propourses.
tooltip("press button ´C´ for cleaning propourses.")
sleep($sleeptime)
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:5]" ) ; press button "1".
tooltip("press button `1`.")
sleep($sleeptime)
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:23]" ) ; press button "+".
tooltip("press button `+`.")
sleep($sleeptime)
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:11]" ) ; press button "2".
tooltip("press button `2`.")
sleep($sleeptime)
ControlClick("[CLASS:CalcFrame]", "", "[CLASS:Button; INSTANCE:23]" ) ; press button "=".
tooltip("press button `=`.")
Sleep($sleeptime)
tooltip("Exiting.")
Sleep($sleeptime*3)

A tip, maybe you can send the accelerator key, to the toolbar.

The problem is that the toolbar buttons don't have control ID's, so 'ControlClick' doesn't work. There are also no accelerator keys, which is why I wrote this script in the first place.

Thanks for the reply...

Bryan

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Maybe sending a message, i´m looking into and it seems a little complicated, but maybe it works.

Toolbar Control Messages and Toolbar Control Notifications

I do it!! :) something rare happends to me, i was about post a different approach for your problem, i was gonna suggest you to use the ControlClick() function and use the coords parameters to first click in the border of the toolbox to open the hidden buttons and later click on the buttons. I started the tests, when i want to pass the tab of the AutoIt Window info, i see the ToolBox tab, and the strange thing is that it had, the last thing I needed to resolve this issue throug the windows messaging system. the ToolBox IDs of every element on it... now i don´t know why it does not show me anymore the IDs, but i could grab one for the testing program and it work, you only need some api function to retrieve the ToolBox IDs...

I have Win7 and the test program is the Snipping Tool(i dont know what is the english version name)

Try it and ask anything.

#include <WindowsConstants.au3>
#Include <winapi.au3>
ShellExecute("SnippingTool.exe")
$winHndl = wingethandle("[CLASS:Microsoft-Windows-Tablet-SnipperToolbar]")
$toolbarHndl = ControlGetHandle($winHndl,"","[CLASS:ToolbarWindow32; INSTANCE:1]")
_sendclick()

Func _sendclick()
    Local $lParam = $toolbarHndl
    Local $BN_CLICKED = 0x0000FFFF
    Local $NID = 219
    local $wParam = _WinAPI_MakeLong($NID, $BN_CLICKED)
    $message = _WinAPI_PostMessage($winHndl,$WM_COMMAND,$wParam,$lParam)
EndFunc   ;==>_sendclick

PD: $NID is the Id of the button in the toolbox. And sorry for my bad english. :| i`m still learning.

Edited by monoscout999

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Welcome to the Forums bcgreen24

You have an MS ToolbarWindow32 class toolbar, so ControlCommand() 'should' work.

If you need additional help, you should post images of the AU3Info utility control and toolbar tabs.

EDIT: typo

$hWnd = ControlGetHandle("Archive Client", "Viewer Control", 106)
;checking control handle class is one form of error checking, toolbar Instance and IsHwnd() checking are others
If _WinAPI_GetClassName($hWnd) == "ToolbarWindow32" Then
    $iCmdIDRight = _GUICtrlToolbar_IndexToCommand($hWnd, 21)
    ;you can also verify correct button by checking for hidden text (if present) with _GUICtrlToolbar_GetButtonText()
    ;If _GUICtrlToolbar_GetButtonText($hWnd, $iCmdIDRight) == "Button name" Then
    Local $hRoot = _WinAPI_GetAncestor($hWnd, $GA_ROOT)
     ;or just substitute your main window handle for $hRoot
    ControlCommand($hRoot, "", $hWnd, "SendCommandID", $iCmdIDRight)
    ;ControlCommand($hWnd, "", $hWnd, "SendCommandID", $iCmdIDRight);will also work
    ;_SendMessage($hRoot, $WM_COMMAND, _WinAPI_MakeLong($iCmdIDRight, $BN_CLICKED), $hWnd) ;same as above
    ;EndIf
EndIf
;ControlCommand can be used with control handle for both title and controlID params
;title would usually be the root parent window of the toolbar (parent could be rebar or other child window)
Edited by rover

I see fascists...

Share this post


Link to post
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
Sign in to follow this  
Followers 0