I see there are a lot of guides about setting hotkeys with autoit. What I want to do though is execute an applications hotkey.
So for instance, I have this to load firefox
Run(#ProgramFilesDir & "\Mozilla Firefox\firefox.exe", "", #SW_MINIMIZE)
Opt("WinTitleMatchMode", 2)
WinWait("Mozilla Firefox")
WinSetState("Mozilla Firefox", "", #SW_MINIMIZE)
Now in firefox's menu, I can see that the combination of Ctrl + D will bookmark a page. Is there any way to perform this action once firefox has been loaded, via autoit?
Thanks
Just use the Send command. Also have a look at SendKeepActive.
With the FireFox window active, just use the Send command.
Send("^d")
There are a few ways to go about doing this. I will list a few different methods below.
Method One - Send Keys
; Below is simply the code you listed in the example to open Firefox and wait for it to load.
Run(#ProgramFilesDir & "\Mozilla Firefox\firefox.exe", "", #SW_MINIMIZE)
Opt("WinTitleMatchMode", 2)
WinWait("Mozilla Firefox")
WinSetState("Mozilla Firefox", "", #SW_MINIMIZE)
; Once FireFox is loaded, and you are at the page you want to bookmark, send Ctrl+D to the page to bookmark it. Since you started the browser Minimized, you will need to activate the page first.
; Activate the window
WinActivate("Mozilla Firefox")
; Send "Ctrl + D"
Send("^d")
Method Two - AutoIt HotKeys
; Create a HotKey controller
HotKeySet("^d", "bookmarkPage")
; Your code is below again.
Run(#ProgramFilesDir & "\Mozilla Firefox\firefox.exe", "", #SW_MINIMIZE)
Opt("WinTitleMatchMode", 2)
WinWait("Mozilla Firefox")
WinSetState("Mozilla Firefox", "", #SW_MINIMIZE)
; The function that is called when "Ctrl + D" is pressed.
Func bookmarkPage ()
; Activate the window
WinActivate("Mozilla Firefox")
; Send they keys
Send("^d")
EndFunc
Method Three - MouseMove (Not recommended)
; Your code below
Run(#ProgramFilesDir & "\Mozilla Firefox\firefox.exe", "", #SW_MINIMIZE)
Opt("WinTitleMatchMode", 2)
WinWait("Mozilla Firefox")
WinSetState("Mozilla Firefox", "", #SW_MINIMIZE)
; Use the mouse move function to move the cursor to the 'Bookmark' icon.
MouseMove(xxxx,xxxx)
Sleep(100)
MouseClick("left")
I HIGHLY recommend not using the last option. I hope one of these worked for you!
Related
I'm using AutoIt and SciTE to create an installation script. The problem I am running into is that there is a tree menu for selection of features. I can select the whole treeview (SysTreeView32), but am not sure how to get inside it to check the boxes without doing a mouse move and click (not a great option).
The Treeview looks like this:
The Control Info from AutoIT is like this:
I'm sure it is possible, just can't figure out how to do it. This is my first attempt a such a script. Creating a response file does not work for this exe for some reason. So - this appears to be my only way out to create a somewhat silent install (not silent anymore, but at least automated).
* EDIT - Current State of Things *
I did figure out how to do some of this, but I still can't figure out if the items is selected before accessing it. So - since it toggles, I could be turning off a feature I want!
$hWnd = WinWaitActive($WindowTitle, 'Select Features')
$tvCtl = ControlGetHandle($WindowTitle, '', 'SysTreeView321')
$firstItem = _GUICtrlTreeView_FindItem($tvCtl, 'eBooks')
_GUICtrlTreeView_SelectItem($tvCtl, $firstItem, $TVGN_FIRSTVISIBLE)
_GUICtrlTreeView_ClickItem($tvCtl, $firstItem, "left", True, 1)
Send('{SPACE}')
I wouldn't think I would have to send the space since I sent the ClickItem, but seems so.
I could also do this:
ControlTreeView($hWnd, '', $tvCtl, 'Select', '#0')
ControlSend($hWnd, '', $tvCtl, ' ')
That will toggle the first one. So - i can count them all up and do it that way.
But when I check for "IsEnabled" or "IsChecked", it always says NO. So - I can't check the ones I need only. I have to hope their status is what I expect.
Here is how I am checking "IsChecked" and "IsEnabled":
If ControlCommand($hWnd, '', $logTool, 'IsEnabled') then
ConsoleWrite('Log Tool - IsEnabled' & #CRLF)
Else
ConsoleWrite('Log Tool - NOTEnabled' & #CRLF)
EndIf
and
If ControlCommand($hWnd, '', $logTool, 'IsChecked') then
ConsoleWrite('Log Tool - IsChecked' & #CRLF)
Else
ConsoleWrite('Log Tool - NOTChecked' & #CRLF)
EndIf
It always comes back NOTEnabled and NOTChecked. I made sure that I ran the same procedure above: FindItem, SelectItem, ClickItem. And, the correct item is highlighted/selected when this procedure is run - I can see that. So - it just isn't returning a proper value.
Opt('WinTitleMatchMode', 2)
$hWnd = WinGetHandle("InstallShield Wizard") ; Notice the correct title
$hTree = ControlGetHandle($hWnd, '', "[CLASS:SysTreeView32;INSTANCE:1]")
; == Now you can interact with the treeview with functions from "GuiTreeView.au3"
EDIT:
Try this
; Select the item so:
_GUICtrlTreeView_SelectItem($hTree, $hItem, $TVGN_CARET)
; Get checked state:
_GUICtrlTreeView_GetChecked($hTree, $hItem)
For more deatails read the AutoIt help.
I'm hoping this is feasible... I made a program using AutoIt that resides in the system tray. One of the tray items runs a function that waits for the user to click on a window to get the window title (it can be any window, not necessarily one made from AutoIt. This part works flawlessly.
I would like for the function to change the mouse cursor to the cross while waiting for the user's click. I have tried using GUISetCursor(3), but from my understanding this only changes the cursor for an AutoIt GUI window.
How could I go about changing the mouse cursor for the user's environment, not just for an AutoIt window?
You can do it so:
#include <Misc.au3>
#include <WindowsConstants.au3>
GetTitleByClick()
Func GetTitleByClick()
Local $hCursor = GUICreate('', 48, 48, -1, -1, $WS_POPUP, $WS_EX_TOPMOST)
WinSetTrans($hCursor, '', 10)
GUISetCursor(3, 1, $hCursor)
GUISetState(#SW_SHOW, $hCursor)
; get title bar position
Local $pos
Do
$pos = MouseGetPos()
WinMove($hCursor, '', $pos[0]-24, $pos[1]-24)
Sleep(10)
Until _IsPressed('01')
GUIDelete($hCursor)
; block mouse
_MouseTrap($pos[0], $pos[1], $pos[0]+1, $pos[0]+1)
; click position - activates the window
MouseClick('left', $pos[0], $pos[1])
; unblock mouse
_MouseTrap()
; get the title of the active window
Local $sTitle = WinGetTitle('[ACTIVE]')
Return MsgBox(0, 'TITLE', $sTitle)
EndFunc
Thatnks to Richard's comment, and a reply in the AutoIt forums that linked me to AutoIt's _WinAPI_SetSystemCursor function, I was able to get this working.
I copied the cross cursor I wanted from %SystemRoot%\Cursors (specifically, I copied cross_i.cur) to put in my script's source directory.
Then, in the function that executes the brute of the program, I added the following lines:
Func FuncName()
;backs up the user's arrow cursor
Local $hPrev = _WinAPI_CopyCursor(_WinAPI_LoadCursor(0, 32512))
;backs up the user's ibeam cursor
Local $iPrev = _WinAPI_CopyCursor(_WinAPI_LoadCursor(0, 32513))
;changes the user's arrow cursor
_WinAPI_SetSystemCursor(_WinAPI_LoadCursorFromFile(#ScriptDir & "\cross.cur"),32512)
;changes the user's ibeam cursor
_WinAPI_SetSystemCursor(_WinAPI_LoadCursorFromFile(#ScriptDir & "\cross.cur"),32513)
; Do the code you want to execute
;restores the user's default cursor
_WinAPI_SetSystemCursor($hPrev,32512)
;restores the user's ibeam cursor
_WinAPI_SetSystemCursor($iPrev,32513)
EndFunc
This allowed me to accomplish what I needed.
I am automating an application using AutoIt where the properties of whole page are constant.
e.g. Instance, Co-ordinates,text etc are same for button,dropdown etc.
Also, the id for all web elements is blank. Only unique property is ControlClick Coords.
#include <Constants.au3>
run("C:\Program Files (x86)\CashRBrowserClient\CashRBrowserClient.exe")
WinWaitActive("Sears Call Center","","10")
WinActive("Sears Call Center")
If WinExists("Sears Call Center") Then
Send("username{TAB}")
Send("password{Enter}")
EndIf
sleep(500)
ControlClick("Sears Call Center", "", "WebViewHost5", "Left")
also tried,
If WinExists("Sears Call Center") Then
;WinActivate("[CLASS:CEFCLIENT];[Instance:1]","[ClassnameNN:WenHost1]")
;sleep(500)
;MouseClick("Left",200,367)
;EndIf`enter code here`
But no luck apart of login.
Need help.
The WinActive function checks if a window is active and returns True or False. In this code, this function is doing basically nothing.
WinActive
It is always a good idea use a WinActivate before the WinWaitActive to avoid problems with the program waiting for ever. A better solution would be:
While Not WinActive($hWin)
WinActivate($hwin)
Sleep(500)
WEnd
WinActivate
WinWaitActive
Try this:
$username = "username"
$password = "password"
Run("C:\Program Files (x86)\CashRBrowserClient\CashRBrowserClient.exe")
WinWait("Sears Call Center")
While Not WinActive("Sears Call Center")
WinActivate("Sears Call Center")
Sleep(500)
WEnd
Send($username)
Sleep(100)
Send("{TAB}")
Sleep(100)
Send($password)
Sleep(100)
Send("{Enter}")
Sleep(100)
So i am working on a project and i got stuck on this part.
I am trying to locate the position of ether the typing caret(The blinking line while typing) or the current text box that is being typed in.
The main part that is hard is i am looking to do this for every input on my computer (Firefox search, Notepad, Renaming files, writing this post...)
I am beginning to doubt that auto-it can do this, i am open to using another language that can do this. (I have not checked any other language but Auto-it yet)
I have tested "WinGetCaretPos()" and a few other random scripts, but they had the same problem, they don't return the correct position.
~Thanks
Not all controls are standard window controls that can be accessed with AutoIt functions. Many programs (especially browsers) have nonstandard controls so "every input" on the computer might be hard to get.
Here is an example of how to get the control information of any active window that is giving focus to a control AND has standard windows controls.
HotKeySet("{ESC}", "Terminate")
While 1
Sleep(500)
GetControlFocus()
WEnd
Func GetControlFocus()
Local $hWinHandle = WinGetHandle("[Active]")
Local $sControl = ControlGetFocus($hWinHandle)
Local $sText = "The active window handle is: " & $hWinHandle & #CRLF
If $sControl <> "" Then
$sText &= "The control with focus in the active window is: " & $sControl & #CRLF
Local $aPos = ControlGetPos($hWinHandle, "", $sControl)
$sText &= "Mouse position: X: " & $aPos[0] & " Y: " & $aPos[1] & #CRLF & "Size: " & $aPos[2] & ", " & $aPos[3]
Else
$sText &= "The active window is not giving focus to a control that AutoIt recognizes."
EndIf
ToolTip($sText, 0, 0)
EndFunc ;==>GetControlFocus
Func Terminate()
Exit
EndFunc ;==>Terminate
You can get the control position of other programs using IUIAutomation and this UDF. But it would not be as simple as using a few standard AutoIt functions.
Instead of returning the currect selected font, it returns 0.
ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("!O")
Send("F")
WinWaitActive("Font")
$select = ControlCommand("Font", "", "[CLASS:ComboLBox; INSTANCE:1]", "GetCurrentSelection", "")
MsgBox(0,"", $select)
That control is actually a "Combo L Box", not a ComboBox. As the AutoIt helpfile says under ControlCommand:
Certain commands that work on normal Combo and ListBoxes do not work
on "ComboLBox" controls.
The ComboLBox is actually a child control of the ComboBox, and is just the drop down part of it. If you use a more advanced window finder like Spy++, you will actually see there is a ComboBox there, with two children (an Edit and the ComboLBox). So your code will work if you change "[CLASS:ComboLBox; INSTANCE:1]" to "[CLASS:ComboBox; INSTANCE:1]".
Furthermore, you can improve your code for triggering the menu item, so that the entire operation can be done in the background.
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Local $IDM_FONT = 33
Local $hWindow = WinGetHandle("Untitled - Notepad")
_WinAPI_PostMessage($hWindow, $WM_COMMAND, $IDM_FONT, 0)
Local $hFontWin = WinWait("Font")
$select = ControlCommand($hFontWin, "", "ComboBox1", "GetCurrentSelection", "")
WinClose($hFontWin)
MsgBox(0,"", $select)
Alternatively, you can interact with the ComboLBox in the same way you would a listbox:
$hLBox = ControlGetHandle($hFontWin, "", "ComboLBox1")
$itemIndex = _GUICtrlListBox_GetCurSel()
$select = _GUICtrlListBox_GetText($hLBox, $itemIndex)
Why ControlCommand doesn't work with this particular type of list box I have no idea. I can only guess that internally they check the control class against "ComboBox" and "ListBox" and return zero if there is no match.
You can use ControlGetText() to read the name of the currently active font, if this is what you want to accomplish.
ShellExecute("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("!O")
Send("F")
WinWaitActive("Font")
$select = ControlGetText("Font", "", "Edit1")
MsgBox(0,"", $select)