AHK Struggles to Enter Values into ComboBox - autohotkey

I am writing an AHK script to automate data entry into a GUI form. There is a drop-down box with a few hundred entries. I know the value I want to select and when I manually type in the number the combo box changes to the appropriate value. When I send the same string in AHK (using Send) it chooses the first item on the list. I have played around with various values of SetKeyDelay (-1 through 2000).
SetKeyDelay 1000
Send %ItemNumber%
SetKeyDelay -1
Any suggestions here?
Thanks
Jonathan

Have you tried other send modes? (Like SendInput, SendPlay, etc...)
Also, if it's a standard Windows combobox, it might be more precise to use messages (like CB_SETCURSEL).

Turns out there was a line up top that was messing me up:
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SendInput ignores the value of SetKeyDelay; the above line was converting all of my "Send"s to "SendInput"s
Thanks-
Jonathan

Related

autohotkey: unable to send numbers as integers (sends like a string)

6::
send 6
return
also tried
$6::send 6 return
$3::send 3 return
$5::send 3 return
Nor did blind or text or replacing send with any of the other sendmode names on the send doc page achieve the effect, which is, for a game to recognize these sends as numbers. These work while typing in chatbox ingame, i.e. "hello14674355", but not when selecting from a menu that use integers, i.e. "press a number from 1-9 to activate an option in a menu". I need ideas/help on what else i can try or do to get this to work. I have a situation where some numbered keys are hotkeys on certain condition (when im not typing for ex), this requires I manually setup the condition where they do send their own value. I need a fix for that. Is there way to retain their normal function as default, but check it only after the hotkey behaviour conditions? When they r in hitkey mode i need them to not send their own value but the hotkey.
Can I get ~3:: if(){... to work infront of 3's native function? then i can return early maybe so it doesnt proc the native 3 sending?

AutoHotKey variable assigning in hotstring

I am trying to make an AutoHotkey hotstring and I couldn't find anything, despite scouring the web.
I'm not quite sure how to explain, but here is an example of what I'm trying to do:
::sendback {thingtosendback}::{thingtosendback}
would (theoretically) send back the input, so sendback wow would just write wow, sendback hi would just write hi etc. Thanks for reading!
You'll probably want to combine a hotstring with the Input command.
Simple example:
:X:sendback::
Input, output, T3, {Enter}
SendInput, % output
return
X option in the hotstring to execute instead of replace text.
T3 option in the Input command to specify a 3 second timeout for it.
{Enter} to mark the end key for the Input command.
Then a check if we timed out or not, if not, we SendInput whatever we typed.
There's a lot of customization you can on both the hotstring and Input command side of things.
Read the documentation to see the possibilities.

When should `Sent` be used over `SentInput` in Autohotkey?

The Autohotkey documentation writes:
SendInput is generally the preferred method to send keystrokes and mouse clicks because of its superior speed and reliability. Under most conditions, SendInput is nearly instantaneous, even when sending long strings. Since SendInput is so fast, it is also more reliable because there is less opportunity for some other window to pop up unexpectedly and intercept the keystrokes. Reliability is further improved by the fact that anything the user types during a SendInput is postponed until afterward.
If SendInput is generally preferred, what are the use cases where sent is better in ahk? When does Sent win the Sent vs. SentInput decision?
I generally use SendInput, as I like the nearly instantaneous input. However I have encountered a few practical limitations:
Some applications like games do not like such fast key strokes because there may be rules against botting.
Some applications can't handle receiving keystrokes that fast and they just get bogged down.
I had an application that allowed pressing tab to move the cursor between fields.
When tabbing into a field the application needed time to acknowledge the arrival of the cursor before it would accept any input. The SendInput command was just to fast for this and frequently lead to mixed results
Pressing tab multiple times was also problematic, and frequently some tabs would be missed by the application and the cursor would end on an unexpected field.
SendInput is too fast to replay something for debugging. For example when I want to watch how the text is being inserted into fields on very complex forms.
In theory with Send you could insert a blob of text and randomly press and hold the shift button to increase entropy while the characters were being typed. Arguably I can't think of why this would be useful.
You should consider switching between SendPlay and SendInput only if you have problems with current setup. SendInput cause problems if you type while a long macro was activated. Your commands might be mixed with macro causing undesired behavior. Tutorial says that SendPlay is "not supported in older games", but I never had problems with that. Someone might comment "you haven't used AHK enough". Well, maybe.
Also, before switching from SendPlay to SendInput you should try to divide your macro into two. For instance, "save control group, do stuff, recall control group" fails in Starcraft2. Splitting it into Send "save control group, do stuff"; Sleep 10; Send "recall control group"; works.

Send command, isn't something wrong with AutoHotkey?

So I have this game, called AirMech. It doesn't recognize mouse buttons as controls (yet) so I tried to use AutoHotkey to circumvent it until it's implemented.
#IfWinActive, AirMech
XButton1::Send c
Didn't work. So I tried SendGame, SendPlay and everything else, didn't work either. I googled it, and found out that some games don't recognize any Send commands at all.
Before giving up, I just tried a simple mapping:
#IfWinActive, AirMech
XButton1::c
It actually worked.
Is it expected than no Send command works, but the latter does? What if I wanted to trigger other actions ('c' plus a MsgBox, for instance)?
AutoHotkey has the ability to send keystrokes in a variety of different ways (SendRaw / SendInput / SendPlay / SendEvent). I'm not quite sure what approach the simple key::key mapping uses, but it must be one of them. My guess is that one of SendRaw, SendInput, SendPlay, or SendEvent will work the same as key::key.
Also #IfWinActive sometimes doesn't work exactly the way you expect, especially with fullscreen games. So I usually test my AHK scripts without the #IfWinActive to make sure they're working correctly. Once it's working, I introduce the conditional.
UPDATE
From http://www.autohotkey.com/docs/misc/Remap.htm:
When a script is launched, each remapping is translated into a pair of
hotkeys. For example, a script containing a::b actually contains the
following two hotkeys instead:
*a::
SetKeyDelay -1 ; If the destination key is a mouse button, SetMouseDelay is used instead.
Send {Blind}{b DownTemp} ; DownTemp is like Down except that other Send commands in the script won't assume "b" should stay down during their Send.
return
*a up::
SetKeyDelay -1 ; See note below for why press-duration is not specified with either of these SetKeyDelays. If the destination key is a mouse button, SetMouseDelay is used instead.
Send {Blind}{b Up}
return
My notes:
I suspect the reason a::b is working but a::Send b is not is because of how a::b breaks button down and button up handlers into two separate mappings. The game's gameloop probably polls the gameplay keys for "keydown" state, which would not be maintained consistently if AHK is synthesizing repeats. Remapping a_down->b_down and a_up->b_up probably makes AHK emulate more accurately the act of holding the key down, which may matter for programs which test for key state in particular ways (GetAsyncKeyState?).
The asterisk in the mapping means "Fire the hotkey even if extra modifiers are being held down."

autohotkey inside autohotkey

Is there a way to write an autohotkey within an autohotkey? For instance, I have an autohotkey that opens some websites in tabs at work for me & I have an autohotkey that when typed puts in my username & password for some of those sites. Is there a way to put the password autohotkey (actd(at symbol)) inside the IE tabs autohotkey? I did some searching, & it doesn't look like {#} can be sent, so I wasn't sure if there was another way to do it.
Your AutoHotKey script can #Include other scripts, assuming they are not #Persistent. You could loop through your list of tabs, and then call one or more other scripts.
As far as sending the # sign, you should be able to use the Send command without problems. If you do encounter a strange problem, then you can try using the SendRaw command or use the syntax: Send {raw}#
If this doesn't answer your question, please paste some code of what you are trying to get working.
What you can do is write two separate scripts. One does not have an autohotkey assigned, but gets called by the initial script. In your case, you have said that you already have a tabopening hotkey, so I will use a VERY rudimentary example of both scripts, but demonstrate how to send the # symbol and call another script from within a hotkey.
The two scripts I would use are:
tabOpener.ahk, and
passwordEntry.ahk
And they would appear as follows:
tabOpener.ahk
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; hotkey is set as WinowsKey+t and checks if FireFox exists, if so, it makes it active, if not, it starts FireFox
~#t::
IfWinExist, ahk_class MozillaWindowClass
{ WinActivate
Send ^t
} else run firefox
;Upon opening a new tab in FireFox, the address bar has already got focus,
;so send the web address (You can use COM functions for this, and are highly
;recommended, but out of the scope of this example)
Send, hotmail.com{Enter}
;Waits until page is loaded. Again COM functions are available as they can tell
;when a page is finished loading, but that is a more involved example.
Sleep 5000
;Calls the password entry script.
Run passwordEntry.ahk
return
passwordEntry.ahk
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
;When using send, adding the {Raw} tag will literally interpret every
;character in the remainder of a string. For instance ^ will send ^
;instead of a Control keypress.
Send {Raw}Username#domain.tld
Send {Tab} {Raw}Password
Hopefully that helps. This example showed the use of the {Raw} tag for sending special characters (http://www.autohotkey.com/docs/commands/Send.htm), in addition to calling a separate script from within one's existing hotkey using Run / Runwait (http://www.autohotkey.com/docs/commands/Run.htm).
;~ Alt+1 to send username (email format) and password
!1::Send, myUsername#mydomain.com{tab}myPassword{enter}
depending on you web browser you could use COM objects to handle this very easily. You would find the user id password fields and then for example:
url := "http://yourwebsite.com"
wb := ComObjCreate("InternetExplorer.Application") ; create broswer object
wb.navigate(url)
wb.visible := true ; sets the browser as visible, defaults as not
While (wb.busy || wb.readyState <> 4)
Sleep 100<br>
wb.document.all.username.value := "yourname#wherever.com"
wb.document.all.password.value := "Pa$$word15"
wb.document.all.btnLogin.click()
this however depends on if you are using IE to access your site or not. Look at COM objects in the docs a bit to get a feel for it, and you will learn some really basic things about the DOM, here: Basic DOM MSDN. where I set the "username" & "password" and "btnLogin" control ids in our javascript, would need to be discovered by looking at your page. you should also check out out this tutorial: AHK Basic COM/JavaScript Tutorial