Jump to content
Sign in to follow this  
Nivse

Register to event

Recommended Posts

Nivse

Hello all,

I'm using autoit to write script over some program which uses "SysListView32" control.

As part of the program, sometime new entries are getting in to the "SysListView32" control accordign to some specific actions the program does.

My goal is to get an event each and every time a new entry got in to the "SysListView32" control and do some specific action.

My question is how can i create an event (something like delegate in C#) or use an existing one for the "SysListView32" control.

thanks,

Nivse

Share this post


Link to post
Share on other sites
Melba23

Nivse,

First, welcome to the Autoit forums. :)

Take a look at the ControlListView function. I have not used it myself, but it looks as it the "GetItemCount" command might be what you are looking for - just keep polling the LV until the count changes.

Give it a try and come back if you have problems.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Nivse

Nivse,

First, welcome to the Autoit forums. :)

Take a look at the ControlListView function. I have not used it myself, but it looks as it the "GetItemCount" command might be what you are looking for - just keep polling the LV until the count changes.

Give it a try and come back if you have problems.

M23

I thought about this kind of solution but wouldn't it require another thread to run and pull the items from LV?

i won't my program to run or wait for user action and when new element is inserted to the LV an action will be taken....

Share this post


Link to post
Share on other sites
Melba23

Nivse,

In pseudo-code I would do something like this:

HotKeySet so you can exit
Old_Count = initial count of LV items

; Start infinite loop
While 1
    New_Count = Current LV item count
    If New_count <> Old-Count Then
        Do_something()
    EndIf
    Old_Count = New_Count
    Sleep a bit to prevent CPU overload
WEnd

Func Do_something()
    Code
EndFunc

Func _Exit
    Exit
EndFunc

Now you just start your script and leave it running. :)

M23

Edit: Speeling - or to be honest Tpying ;)

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Nivse

Nivse,

In pseudo-code I would do something like this:

HotKeySet so you can exit
Old_Count = initial count of LV items

; Start infinite loop
While 1
    New_Count = Current LV item count
    If New_count <> Old-Count Then
        Do_something()
    EndIf
    Old_Count = New_Count
    Sleep a bit to prevent CPU overload
WEnd

Func Do_something()
    Code
EndFunc

Func _Exit
    Exit
EndFunc

Now you just start your script and leave it running. :)

M23

Edit: Speeling - or to be honest Tpying B)

Well it's a bit more complicated then that...

let me explain:

My program control on softphone application.

with my program i can automaticaly send commands in text, "dial" for example and with autoit i press the relevant buttons on the softphone application.

this application also has a status window - the list view control.

if i gave a "dial" instruction then i get dial a new entry in the list view - "dialing"

now i want to keep a state machine to know in which state im currently in (dialing, ringing, answered, idle etc...) all these states are a result in the LV from the commands i send.

when i send the command -"dialing" for example i have no problem since i know the state - "dialing"

but... in the other side someone is answering maybe and this command doesn't sent by me but from the other side thus i have a schange in the state that didn't came from my command (dialing --> answered).

this is way i need to read from LV to get the states directly from it and not from the command certain side is sending.

so my program always runs and wait for commands i just need an event for cases where a new entry got in the LV so i would update my state and continue waiting for user command.

i don't see how can implement you solution above in my program B)

please correct me if im wrong.

hope you have a better solution for me ;)

thanks a lot,

Nivse

Share this post


Link to post
Share on other sites
Melba23

Nivse,

Firstly, when you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. :)

Now, my understanding of the ControlListView function is that it will work on controls in windows other than those created by your own script. The "GetItemCount" command will get you the number of items in the list - it should then be simple simple to use the "GetText" command to tell you what the new item is - if it is one produced by your own script, then ignore it; if it is produced by the other side, then action it.

For responses to your own inputs I would suggest something along these lines: Your script places "dialing" into the LV - you recognise that a new item has been put into the LV, and you know it is one of your own. You therefore just keep re-reading that item using the "GetText" command and see what the response is. If the text becomes "dialing --> answered" then you take certain actions, if it becomes "dialling --> no-one home" than you do something else.

So I suggest that you go and try to script something along the lines of the suggestions above and then come back if you run into problems. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Nivse

thanks a lot ,

It really helped, i will try it tomorrow and come back if i will have more issues.

thanks,

Niv

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×