Using Autohotkey to select an option from a dropdown on a webpage - select

I am trying to write a script to select something from a drop down on a webpage and then tab to the next option and input text, then enter. FYI, this is my first script.
I have to create groupings and select from different areas. I have seen places where people have scripts to select certain things but says that can only work in IE browser. I will be using either firefox or chrome but not IE.
^q::Click, 284, 427 ;
Send {Up 10}
Send {Tab} ;
sleep 50 ;
Send BWI{Enter}
return
So what I want it to do is when I press control q, it will go to position 284,427 and click. The dropdown defaults to the bottom option. So I put in code to go up 10 which would select the 10th option from the bottom. Then I want it to tab. That will select the 10th option and go to the next text box at which point it will enter the text BWI and then enter. The BWI is a filter that will show all of the items that have BWI in their name.
Currently, it goes to the dropdown and clicks. Then it does nothing else.

To have more than one command executed by a hotkey, put the first line beneath the hotkey definition and make the last line a return:
^q::
Click, 284, 427
Send {Up 10}
Send {Tab}
sleep 50
Send BWI{Enter}
; ...
return
https://autohotkey.com/docs/Hotkeys.htm#Intro

Related

Perform a sequence of two mouse clicks

I try to automate a process where I have to perform two mouseclicks. One should go to an absolute position and perform a left click:
Click, 492, 256, Right
And the second should select a value from the dropdown box. The exact (absolute) location of the value in the dropdown list which should be selected is:
Click, 801, 571, Left
I hacked together this code:
#r::
Click, 492, 256, Right
Sleep 1000
Click, 801, 571, Left
But this does not seem to work. It performs a left click at in the situation I want but the dropdown box is not selected. Any thoughts on what I am doing wrong at the second Click?
It could be that the dropdown box doesn't allow "instantaneous" clicks, I had this problem also some time ago. My first post here, so sorry if format is bad...Try the following:
#r::
Click, 492, 256, Right
Sleep 1000
MouseMove, 801, 571
Sleep 100 ; if code works, try to deactivate this one
Click, Down Left
Sleep 100
Click, Up Left
If this doesn't work:
Try to lower Speed on MouseMove somewhat, via additional option.
Try changing SendMode to Input for this part of your script

autohotkey type in another window with gui

Autohotkey Example Needed
Need some help, please. I've searched and can't seem to find an example of what I need.
What I want to do is create a ahk dialog box with a button (I can do this part), and when I click on it, it will type some text into another window. Basically, I want want to offload the "shortcut" to a "mouse click". But, without mapping a shortcut.
Something like this:
When user clicks BOX1, "text" is stored. Then, when user clicks elsewhere, vBOX1 is typed into the cursor location of the window activated by that click
I hope I'm explaining this succinctly. Any help would be appreciated.
Here are two possible alternatives:
First alternative expands #scso's suggestion:
~LButton::
sleep, 200 ;give the window below the cursor some time to get activated
Send, %vBOX1%
return
Now this may seem fine but what it actually does is type the text EVERY time you click the mouse in ANY window. Let's put an additional check so if vBOX1 is empty it doesn't type anything.
~LButton::
sleep, 200 ;give the window below the cursor some time to get activated
If (vBOX1 != "")
{
Send, %vBOX1%
vBOX1 := "" ; clears the contents of vBOX1
}
return
Second alternative:
You use the mouse clicks normally and the text gets typed only when you do Control + Click.
So in order to type the text you need to click once to select the window and then control+click to do the actual typing
~^LButton::
Send, %vBOX1%
vBOX1 := "" ; clears the contents of vBOX1
return
You can expand both alternatives by adding commands for detecting the active window and then typing the text or changing the mouse click combination to something else.

In AutoHotKey, how to use mouse to select text in the background?

I have a legacy text based database whose data cannot be exported. I have to use mouse to select data on screen, and do ctrl+c to copy them to a txt file. I have managed to do this using AutoHotKey. Now I want this to be run in the background without interfering my other job on the computer.
The database will be an inactive hidden window. I could use ControlClick and ControlSend to type things. But I cannot select a piece of text like the way I do when the window is active. I tried the following but it does not work:
ControlClick, X%dat_x1% Y%dat_y1%, ahk_id %database_window_id%,,,,NA D
ControlClick, X%dat_x2% Y%dat_y2%, ahk_id %database_window_id%,,,,NA U
I guess it's because the mouse isn't moved using ControlClick. Can anyone please help me with this? Thanks.
"I guess it's because the mouse isn't moved using ControlClick."
If WinGetText (or Send, ^a^c to select all and copy) and then some regex pattern can't be used, maybe, after the click, you could just use Send, +{Right} to select..? Or for example Send, ^+{Right 7} to select 7 whole words/spaces.
You can query the database itself if you had the right permissions.
I've used this in the past: https://autohotkey.com/board/topic/90862-acclib-access-database/

Autohotkey: task to copy from browser and paste on text editor

I'm trying to build a script that uses both a browser and a texteditor. The workflow I can summarize as follows:
Right click on a video for streaming
Click on the option to copy the redirection link
Switch to a text editor (Slickedit in my case)
Paste the copied link
Go back to the browser and await next command.
I want to automate this with a single key press while I am standing on the link with the mouse. This has been
my attempt:
^+!a::
Click Right, 392, 64 ;execute in browser
Click Left, 410, 79 ;
Send, !{Tab} ;switch to text editor
Send, ^V ;paste in text editor
Send, !{Tab} ;switch back to browser
return
The script isn't working correctly because it appears not to be executing the ^V command.
I suspect it's because it is executing it before Slickedit is even active. How can I syncronize
these KeyPreses so that they are executed at the right times? Also is there a nicer way for me to
switch to Slickedit without relying on the alt-tab?
There are a few things you could use to make your script better. WinActivate, clipboard, and improved mouse movement seem to be good ones to add.
^+!a::
clipboard = ; clears clipboard
Click Right ; execute in browser
MouseMove, 18, 15, 50, R ; Moves mouse relative to start location
Click Left
ClipWait, 2 ; Waits 2 seconds for clipboard to contain something
WinActivate, Slickedit ; Switch to text editor
WinWaitActive, Slickedit
Send % clipboard ; paste in text editor
WinActivate, ahk_class Chrome_WidgetWin_1 ; or your browser of choice
Return
Use the included Window Spy to find the correct Window titles or classes to be used in the WinActivate commands.

How to obtain textual contents from a window

I have a window that displays a book. In two smaller boxes below, there is page number and volume information of the book that is open. I can get that information easily as follows:
ControlGetText, volume, ThunderRT6TextBox3
ControlGetText, page, ThunderRT6TextBox2
Then my script makes my mouse pointer move to a button. It clicks it, and a new window pops open. In that window, there is more textual information related to the book, such as publisher, name author, edition etc. I want to retrieve that information. But when I try the same strategy it is not working, eg:
ControlGetText, data, RichTextWndClass3
The only difference between the two cases, is that those two small boxes are editable, you can enter text whereas this window is static.
I tried many other options such as:
SendEvent ^a
Which is equivalent to control + a, which should select everything. I tried putting pauses but it would never select. I tried the script to manually double click on that window. It works, and one word gets select like that. Even then SendEvent ^a doesn't do anything.
However, if I do SendEvent ^{insert}, then the selected word gets copied to my clipboard.
I experimented with more combinations:
ControlSend ahk_class ThunderRT6FormDC, ^a
ControlSend ClassNN RichTextWndClass3, ^a
and
ControlSend ThunderRT6FormDC, ^a
ControlSend RichTextWndClass3, ^a
None of them work. All text selection does not manifest itself in that window.
The only alternative remaining for me is to make the script do a manual selection of the entire text. However, this is slow and very ridiculous. Moreover, in Window Spy under the section: Visible Window Text, the text is all there. I tried many other possibilities and I am at the end of my wits. How am I to harvest that text directly?
EDIT--
The text of the window shows in Window Spy under the heading: TitleMatchMode=slow Visible Text, NOT the heading: Visible Window Text
EDIT--
I spoke to you about two windows. The first one in which i get volume and page number. The second one which needs to pop up by pressing a button.
Both these windows have the same class-name:
ahk_class ThunderRT6MDIForm
Is that problematic in any way?
EDIT--
The conclusion is that it is impossible for me to get that text from the second window directly. As such, I opted for the lame, boring manual method. I send out a {shift down} to the active window and then do a click at the bottom of the window. Then I save the selection to my clipboard. It works, but it is just stupid. Please help me find a more elegant solution than this one.
This is the code I used:
ControlGetText, volume, ThunderRT6TextBox3
ControlGetText, page, ThunderRT6TextBox2
Click, 110, 70
sleep 1000
SendInput {shift down}
click 29, 490
SendInput {shift up}
sleep 1000
SendInput, ^{ins}
sleep 100
It is funny to note that real keyboard keys, such as a b c are not possible. But I am able to send a ctrl, shift and an ins. As I noted above, ^c was also giving issues just like ^a was giving issues.
This routine will do the job of getting and returning from the active window the following text sections:
- EdtWindowTextFastVisible
- EdtWindowTextSlowVisible
- EdtWindowTextFastHidden
- EdtWindowTextSlowHidden
MyGetWindowText(ByRef EdtWindowTextFastVisible, ByRef EdtWindowTextSlowVisible, ByRef EdtWindowTextFastHidden,ByRef EdtWindowTextSlowHidden)
{
; Source: https://code.google.com/p/autohotkey-cn/source/browse/trunk/Source/AHK_Window_Info/AHK_Window_Info_v1.7.ahk?r=6
EdtWindowTextFastVisible =
EdtWindowTextSlowVisible =
EdtWindowTextFastHidden =
EdtWindowTextSlowHidden =
WindowControlTextSize = 32767
VarSetCapacity(WindowControlText, WindowControlTextSize)
WinGet, WindowUniqueID, ID, A
;Suggested by Chris
WinGet, ListOfControlHandles, ControlListHwnd, ahk_id %WindowUniqueID% ; Requires v1.0.43.06+.
Loop, Parse, ListOfControlHandles, `n
{
text_is_fast := true
If not DllCall("GetWindowText", "uint", A_LoopField, "str", WindowControlText, "int", WindowControlTextSize)
{
text_is_fast := false
SendMessage, 0xD, WindowControlTextSize, &WindowControlText,, ahk_id %A_LoopField% ; 0xD is WM_GETTEXT
}
If (WindowControlText <> ""){
ControlGet, WindowControlStyle, Style,,, ahk_id %A_LoopField%
If (WindowControlStyle & 0x10000000)
{ ; Control is visible vs. hidden (WS_VISIBLE).
If text_is_fast
EdtWindowTextFastVisible = %EdtWindowTextFastVisible%%WindowControlText%`r`n
Else
EdtWindowTextSlowVisible = %EdtWindowTextSlowVisible%%WindowControlText%`r`n
} Else
{ ; Hidden text.
If text_is_fast
EdtWindowTextFastHidden = %EdtWindowTextFastHidden%%WindowControlText%`r`n
Else
EdtWindowTextSlowHidden = %EdtWindowTextSlowHidden%%WindowControlText%`r`n
}
}
}
;EdtWindowTextFastVisibleFull := ShowOnlyAPartInGui("EdtWindowTextFastVisible", EdtWindowTextFastVisible, 400)
;EdtWindowTextSlowVisibleFull := ShowOnlyAPartInGui("EdtWindowTextSlowVisible", EdtWindowTextSlowVisible, 400)
;EdtWindowTextFastHiddenFull := ShowOnlyAPartInGui("EdtWindowTextFastHidden", EdtWindowTextFastHidden, 400)
;EdtWindowTextSlowHiddenFull := ShowOnlyAPartInGui("EdtWindowTextSlowHidden", EdtWindowTextSlowHidden, 400)
Return
}
There is an autohotkey script that emulates most of the window spy logic. It is called AHK_Window_Info_v1.7.ahk. The nice thing is... you can run it to see if your second window text if visible to this script and if so... the logic needed to pull the information is available inside the script. Here is a link to the webpage and the script is available through SKANs dropbox link on that page. http://www.autohotkey.com/board/topic/8204-ahk-window-info-17/