Question

While making AutoHotkey-script I encountered the following problem. I need navigate listbox (one position to lower direction). If the current selected line is a bottom line of visible listbox area, then navigation will take longer than if the selection is above the last line. There is an illustrating video of this behavior. (EDIT: As I understand it, there is an extra-time to redraw listbox)

The following script doesn't work for the selected bottom-line.

Send, {tab}   ; Set focus to ListBox
Send, {down}  ; Navigate Listbox
Send, {enter} ; Submit selection

So, I can insert Sleep, 200 after second line. However, there maybe more elegant solution. If such a solution exists, describe it to me, please.

Was it helpful?

Solution

I'm not able to reproduce the behavior you're talking about.

There really isn't anything inelegant about adding one Sleep command if it makes things work well.
Sleep is very often needed when using the Send command for things to work smoothly, in various applications. This is because the Send command sometimes sends artificial keystrokes faster than the application is designed to handle. I have needed to write scripts like:

Send, {x down}
Sleep, 50
Send, {x up}

for it to work in several applications, to simulate the press duration.
There is of course SetKeyDelay but then you don't have as fine of control.

Another option is using GuiControl to select things.
Here is a rough example:

Gui, Add, DropDownList, vColorChoice, Black|White|Red|Green|Blue
Gui, Add, ListBox, vChoice Choose1 AltSubmit h120, Red|Green|Blue|Black|White
Gui, Show, h156

loop 4
{
Gui, Submit, nohide
sleep, 1000
GuiControl, Choose, Choice, % Choice + 1
Send, {enter}{tab}
} Return

It's a demonstration, not a practical script. To select something specific it would look like:

GuiControl, Choose, Choice, 3
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top