Script idea for an expert: typing in list view

Get help with using AutoHotkey and its commands and hotkeys
User avatar
derz00
Posts: 308
Joined: 02 Feb 2016, 17:54

Script idea for an expert: typing in list view

17 Jul 2017, 14:27

The program we use for accounting developed a bug in a recent update, that they claim they can't fix until sometime later this year. If there happens to be an AHK expert around here that would like something to conquer, would they be able to find a way to help me out?

In one of the windows of this accounting program, you can open up this dialogue window to choose a stored frequent transaction. Normally you could type the first letter of the line you want, and it would select that one, you hit enter, and whoopee, you have it! But with this bug, typing in this list view box brings up an error window. This window does have error information, but I don't know if it would help.

Edit: So, what I need is, when typing a letter in this window, inspect the list, (they aren't always in the same order), and select the first line that starts with that letter. When pressing the letter again, go to the next line with that letter.

Would there be a way for me to inspect this window so you would know how to work with it? Or does this all not make sense yet? I can try to explain further.

I like using the mouse as little as possible, so this would be a great help, to me, and others that use this program.

Thanks a million, and load on the questions so I know what you need to know. Likely this is a very fuzzy explanation. And also very likely that this is impossible, or else a monstrous project that would take as long as it should take the software people to fix the bug.

Edit 2: it's not that I don't want to do the work myself, its just that it's way beyond my level, and possibly even impossible, I just have no way of knowing.
Image
User avatar
Exaskryz
Posts: 2621
Joined: 17 Oct 2015, 20:28

Re: Script idea for an expert: typing in list view

17 Jul 2017, 14:38

I wouldn't know the answer. There may be ways to use ControlGet on a listview, but I don't know if you can get the list of options in it, or just what is actually in the edit field (Where you're typing, and the listview is supposed to populate that edit field).

But I just want to clarify: When you're typing, do you see the list of options available to you? And it's just an error when you try to select it? The way you said "But with this bug, typing in this list view box brings up an error window." seemed to imply you don't see a list of options. Or is it that as soon as you type, it is trying to make a selection, so it gives the error -- in other words, you can see the list of options only when you haven't typed anything?

Quick edit: Actually, listview with ControlGet says it can indeed get the List (explained near the top of the documentation), so you may have a solution through that.

You can also use ControlGetFocus to figure out if you're focusing on a listview or not - if you know the names of each control for the listview.

These names come from the Window Spy which can be accessed by right-clicking the tray icon (by the system clock) of a running script.
User avatar
derz00
Posts: 308
Joined: 02 Feb 2016, 17:54

Re: Script idea for an expert: typing in list view

17 Jul 2017, 14:43

Congrats on 2000th post. And lightning fast too.

Yes, the list of options is there like normal. As soon as I hit one key, an error message comes up. I can close that box, and use the mouse to select what I want.

Oh, and I also see now that using the arrow keys, up and down, works. And also, it is possible to sort the list by name, and so since the list doesn't change much, I could write a simple script to press arrow down %x% times according to which key I press... But if there is a more "proper" way to do it, I want to learn! :)
Image
User avatar
Exaskryz
Posts: 2621
Joined: 17 Oct 2015, 20:28

Re: Script idea for an expert: typing in list view

17 Jul 2017, 23:11

Here's what I'm thinking might work.

1) You could have the script trigger when it detects that error box. You can get it with a WinWait, and you can even try to check the text to make sure it's the error box related to trying to activate this.

2) Otherwise, you can try to have it trigger whenever it's in a listview.

3) Either way, you want focus on this listview, and use the ControlGet command to pull the list off the listview.

4) Using either your own GUI or an InputBox or the Input command (though seeing what you've typed would be trickier), you could use a RegEx command to have it find the selections that begin with what you typed. But actually, as I'm thinking about this, consider making your own GUI with a listview itself. Gui, Listview control… Reading up on that, is this a listview, or a Gui, Listbox control ? I'm less familiar with a listview, but seems you could still work around it by recreating the control in an AHK window, getting the selection you want, and then using Control or ControlSetText to make a slection in it.

If it ends up being a listbox, you can use AltSubmit to get the number of that entry in the list, and use your Send {Down %x%} idea.
User avatar
jeeswg
Posts: 2677
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Script idea for an expert: typing in list view

18 Jul 2017, 00:01

Try this:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Btw I would suppose PgUp/PgDn/Home/End also work. If you do Send b etc, does that cause an error message? Or ControlSend or if you use this function (which uses the WM_CHAR message):

PostMessage plz help - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=30925&p=144465#p144465

==================================================

Generally for listviews you can use listview messages to achieve things like setting which items have the focus/selection. I will be returning to such a function after I complete 3 projects that I'm currently working on.
List View Messages (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/ff485961(v=vs.85).aspx

Sometimes messages are simple, you do PostMessage/SendMessage by itself/SendMessage and get the return value (ErrorLevel), but sometimes you need to deal with memory in the address space of an external process, and take into account whether your (AutoHotkey) and their programs are x32 or x64 (4 possibilities). This is the case for setting the listview item focus/selection, but I have done it before, and when you see the finished function it won't look too bad.

From:
list of handy dll functions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=34017

The 6 key dll functions when you want to get/set external control text:
- OpenProcess
- VirtualAllocEx
- WriteProcessMemory
- ReadProcessMemory
- VirtualFreeEx
- CloseHandle
(Plus PostMessage/SendMessage, which are AHK commands but also the names of dll functions.)
User avatar
derz00
Posts: 308
Joined: 02 Feb 2016, 17:54

Re: Script idea for an expert: typing in list view

18 Jul 2017, 06:32

It's a listbox, then I guess. Just a simple list in a little window, where you can select one option.

I will try your script jeeswg, I hope today, but I am busy at work. However this would save me some time.

Exaskryz: So you're saying, replicate the list in my own GUI, in the same order, then use AltSubmit when I hit enter to store the position of the selected line? Then Send {down %x%} in the original window.

Hmm, this is interesting. Thanks for your generous help so far...
Image
User avatar
jeeswg
Posts: 2677
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Script idea for an expert: typing in list view

18 Jul 2017, 09:32

What ClassNN does it report back if you use AutoHotkey's window spy? E.g. SysListView321, ListBox1.

If it's a ListBox control, try this:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
derz00
Posts: 308
Joined: 02 Feb 2016, 17:54

Re: Script idea for an expert: typing in list view

18 Jul 2017, 10:02

This is the ClassNN: WindowsForms10.LISTBOX.app.0.9585cb_r38_ad11

I guess I should have checked that out sooner.

What is running this script supposed to do? Yes, that's right I'm an idiot.
Image
User avatar
jeeswg
Posts: 2677
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Script idea for an expert: typing in list view

18 Jul 2017, 10:13

The script gets a list of the ListBox items, and if one of them has a certain string, selects it.

The ClassNN you have mentioned probably isn't a standard listview/listbox control, and may not be compatible with the standard AHK commands. Although you could test:
ControlGet, vText, List,, % vCtlClassNN, A

The Acc script may work to list the item text, and accDoDefaultAction might also work. So you could try to modify my original Acc script, in case it works.

For different ways that Acc can interact with controls:
IAccessible interface (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/dd318466(v=vs.85).aspx

Well, the two useful techniques that *might* work: accDoDefaultAction and accSelect. You can search for examples on the forum.
User avatar
derz00
Posts: 308
Joined: 02 Feb 2016, 17:54

Re: Script idea for an expert: typing in list view

18 Jul 2017, 10:30

It works great:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Pressing q selects Bell Mobility.

So, I can see now that something should work here... Unfortunately right now I don't have time to mess around very long... We'll see how the day works out.
Image
User avatar
derz00
Posts: 308
Joined: 02 Feb 2016, 17:54

Re: Script idea for an expert: typing in list view

18 Jul 2017, 10:32

This didn't work. The message box is blank...???

Code: [Select all] [Download] GeSHi © Codebox Plus

q::
ControlGet, vText, List,, % vCtlClassNN, A
msgbox % vText
exitapp
Image
User avatar
jeeswg
Posts: 2677
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Script idea for an expert: typing in list view

18 Jul 2017, 10:40

From your example above, it looks as though this will work, and even the item selection via PostMessage:

Code: [Select all] [Download] GeSHi © Codebox Plus

vCtlClassNN := "WindowsForms10.LISTBOX.app.0.9585cb_r38_ad11"
ControlGet, vText, List,, % vCtlClassNN, A
MsgBox, % vText

So it seems that your problem may be solved. After selecting the text, you can probably use SendInput {Enter} or ControlSend, or perhaps there is an OK button that you can invoke (e.g. ControlClick), to finish the job.
User avatar
derz00
Posts: 308
Joined: 02 Feb 2016, 17:54

Re: Script idea for an expert: typing in list view

18 Jul 2017, 12:41

Thanks so much for you help. I now face the problem of engineering this concept into working code. I tried the following code, but just using Input isn't very good because the window is also receiving the input. Would there be a better way to do it, other than just making a custom GUI?
Well, as complicated as this gets, that might be a more reliable solution... :think:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Image
User avatar
jeeswg
Posts: 2677
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Script idea for an expert: typing in list view

18 Jul 2017, 12:51

I'm not quite sure why you mention the Input or Gui commands. AFAICT you have a control, sending letters causes a crash (or rather just an error dialog that has to be dismissed, perhaps via Esc), so you use another method to directly choose an item, then once that item is selected, you would want to send Enter (or something), and the program reacts to the item choice as it normally would. Am I missing something?
User avatar
derz00
Posts: 308
Joined: 02 Feb 2016, 17:54

Re: Script idea for an expert: typing in list view

18 Jul 2017, 13:04

Yes. I guess I have failed to explain sufficiently. I was wanting to have the same feature as the window had before: pressing the first letter of the line you want to select it. But I think I can find some other way. What I don't want is trigger the error dialog. It sometimes comes fast, and sometimes slow, so I don't want to mess with it, even if it doesn't crash the program. But I'll mess around with it more, and find something that will work.

Humph, wasn't watching. This is my 100th post... :(
Last edited by derz00 on 18 Jul 2017, 16:50, edited 1 time in total.
Image
User avatar
jeeswg
Posts: 2677
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Script idea for an expert: typing in list view

18 Jul 2017, 13:19

In that case what you could do is add hotkeys for each letter (with the appropriate #IfWinActive criteria), and select the first item that begins with that letter, the first such item below the currently selected item. The ControlGet help page gives ways to get the text or position of the focused item in a listbox: the Choice subcommand or LB_GETCURSEL.

ControlGet
https://autohotkey.com/docs/commands/ControlGet.htm

[EDIT:] Btw I said this earlier:
'I would suppose PgUp/PgDn/Home/End also work. If you do Send b etc, does that cause an error message? Or ControlSend or if you use this function (which uses the WM_CHAR message'

Did you try any of these techniques? If Send/ControlSend/WM_CHAR worked, then that could simplify things enormously.
User avatar
derz00
Posts: 308
Joined: 02 Feb 2016, 17:54

Re: Script idea for an expert: typing in list view

18 Jul 2017, 16:57

No, Send and ControlSend also causes the error.

Checking out WM_CHAR. I don't know enough about Functions or messages. Can you show me an example of using that script to send "Hello World" into notepad? But no need to bother yourself any longer with this noob

Ooops hold on I see one on that page now.
Image
User avatar
derz00
Posts: 308
Joined: 02 Feb 2016, 17:54

Re: Script idea for an expert: typing in list view

19 Jul 2017, 08:34

Hi,
Another question about your PostMessage. It works good, and I have created a simple GUI to be able to have the same list box features. But for some reason if I Send Enter after the PostMessage, it selects the first one in the list, rather than the one that PostMessage has highlighted. As you can see in the code below, I added {Up}{Down} as a cheat fix. Can you help me see the problem?


Code: [Select all] [Download] GeSHi © Codebox Plus

PostMessage, 0x186, % pos, 0,, % "ahk_id " hCtl ;LB_SETCURSEL := 0x186
Sleep, 150
Send, {up}{down}{enter}
return
Image
User avatar
jeeswg
Posts: 2677
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Script idea for an expert: typing in list view

19 Jul 2017, 08:53

This sounds similar a problem with ComboBox controls, that I believe I did not have in Windows XP, but I did have in Windows 7. Does the Gui command and 'Choose' work?

Before I came up with a programmatic solution for ComboBoxes I used the workaround solution you mentioned, by sending a keypresss to the control (e.g. Home/End/a letter/an arrow key), the control did register the change in selection. It's similar also to TBM_SETPOS (change trackbar position) versus TBM_SETPOSNOTIFY (change trackbar position and notify the control) e.g. trackbars for setting the volume.

[see the JEE_ComboBoxNotify function]
GUI COMMANDS: COMPLETE RETHINK (latest: get/set system fonts, ComboBox choose string notify) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=25893&p=132424#p132424
windows - How to simulate selection change in the "file type" ComboBox in GetSaveFileName dialog from a separate process? - Stack Overflow
https://stackoverflow.com/questions/28952380/how-to-simulate-selection-change-in-the-file-type-combobox-in-getsavefilename
c++ - (WinAPI) Simulating item selection in ComboBox - Stack Overflow
https://stackoverflow.com/questions/23136283/winapi-simulating-item-selection-in-combobox

Perhaps I can make a JEE_ListBoxNotify function using one of these:
List Box Notifications (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/ff485968(v=vs.85).aspx
User avatar
derz00
Posts: 308
Joined: 02 Feb 2016, 17:54

Re: Script idea for an expert: typing in list view

19 Jul 2017, 09:14

OK, I will check into your options sometime. The funny thing is, I thought pressing Enter manually works. But maybe I am remembering wrong. What I have works, but I will check this out later. Thanks.
Image

Return to “Ask For Help”

Who is online

Users browsing this forum: A_User, Google [Bot], Yahoo [Bot] and 56 guests