LearningEW Posted June 29, 2021 Author Posted June 29, 2021 It working in background but its doing shift+ select .....thats making it select all stocks and its not scrolling through each stock....
Luke94 Posted June 29, 2021 Posted June 29, 2021 Whoops! Try this: #include <GuiListView.au3> Global $g_hWnd Global $g_hListView Global $g_iCount Global $g_iIndex $g_hWnd = WinGetHandle('AmiBroker') ; Get AmiBroker window handle If IsHWnd($g_hWnd) = 1 Then ; Check the window handle is valid If WinActive($g_hWnd) = 0 Then ; Check if AmiBroker is NOT active WinActivate($g_hWnd) ; If it's NOT active, activate it WinWaitActive($g_hWnd, '', 5) ; Wait for the handle to become active EndIf While 1 ; Loop forever $g_hListView = ControlGetHandle($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]') ; Get the ListView handle $g_iCount = (_GUICtrlListView_GetItemCount($g_hListView) - 1) ; Get the number of items in the ListView $g_iIndex = 0 Do _GUICtrlListView_SetItemSelected($g_hListView, -1, False) ; Deselect all items ; _GUICtrlListView_ClickItem($g_hListView, $g_iIndex, 'Left', False, 2, 0) ; Double click the ListView Item _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex) _GUICtrlListView_EnsureVisible($g_hListView, $g_iIndex) ; Scrolls the ListView to the given index - which we're increasing by one below $g_iIndex += 1 Sleep(2000) ; Wait 2000ms (2 seconds) Until $g_iIndex > $g_iCount ; Loop until we've reached the end of the ListView _GUICtrlListView_EnsureVisible($g_hListView, 0) ; Once we've reached the end of the ListView above, move back to the top of the ListView Sleep(15000) ; Wait 15000ms (15 seconds) - once we've waited, the While loop will restart WEnd EndIf
LearningEW Posted June 29, 2021 Author Posted June 29, 2021 (edited) Its highlighting one stock at a time and moving in background also. But its not selecting stock, as on selection the chart should be shown like it was happening on the click function script. In this its highlighting the stock name and moving to next without chart changing. Normally i click 1st chart and then use arrow key to move down, and as we move through the arrow keys the charts/stocks keep changing. Edited June 29, 2021 by LearningEW
Luke94 Posted June 29, 2021 Posted June 29, 2021 Try this: #include <GuiListView.au3> Global $g_hWnd Global $g_hListView Global $g_iCount Global $g_iIndex $g_hWnd = WinGetHandle('AmiBroker') ; Get AmiBroker window handle If IsHWnd($g_hWnd) = 1 Then ; Check the window handle is valid If WinActive($g_hWnd) = 0 Then ; Check if AmiBroker is NOT active WinActivate($g_hWnd) ; If it's NOT active, activate it WinWaitActive($g_hWnd, '', 5) ; Wait for the handle to become active EndIf While 1 ; Loop forever $g_hListView = ControlGetHandle($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]') ; Get the ListView handle $g_iCount = (_GUICtrlListView_GetItemCount($g_hListView) - 1) ; Get the number of items in the ListView $g_iIndex = 0 _GUICtrlListView_SetItemSelected($g_hListView, -1, False) _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex) Do ; _GUICtrlListView_SetItemSelected($g_hListView, -1, False) ; Deselect all items ; _GUICtrlListView_ClickItem($g_hListView, $g_iIndex, 'Left', False, 2, 0) ; Double click the ListView Item ; _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex) _GUICtrlListView_EnsureVisible($g_hListView, $g_iIndex) ; Scrolls the ListView to the given index - which we're increasing by one below ControlSend($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]', '{DOWN}') $g_iIndex += 1 Sleep(2000) ; Wait 2000ms (2 seconds) Until $g_iIndex > $g_iCount ; Loop until we've reached the end of the ListView _GUICtrlListView_EnsureVisible($g_hListView, 0) ; Once we've reached the end of the ListView above, move back to the top of the ListView Sleep(15000) ; Wait 15000ms (15 seconds) - once we've waited, the While loop will restart WEnd EndIf That'll de-select all items and select the first item. Then use the down arrow key to circle through. I'm not sure if ControlSend will work without focus though.
Luke94 Posted June 29, 2021 Posted June 29, 2021 If that doesn't work, try adding: ControlFocus($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]') Inbetween: _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex) ; <--- here Do
LearningEW Posted June 29, 2021 Author Posted June 29, 2021 Thanks Luke this seems to be working. Will check in tomorrows market time and update again.
LearningEW Posted June 30, 2021 Author Posted June 30, 2021 (edited) 15 hours ago, Luke94 said: Hi Luke, The script has stopped working, its not doing any thing after system went to sleep and relogged in , both the double click and and arrow. Have not changed the code Update it started working, but after it goes to last stock/chart then it moves to top but then doesnt select the stock, just moves the list. Edited June 30, 2021 by LearningEW Update
LearningEW Posted June 30, 2021 Author Posted June 30, 2021 In addition to above stock selection: I put this AutoItSetOption("TrayIconDebug", 1) as sometimes the scripts stops working. And when i see on the Autoit tray icon it shows line 32 sleep(15000)
Luke94 Posted June 30, 2021 Posted June 30, 2021 (edited) Try this: #include <GuiListView.au3> Global $g_hWnd Global $g_hListView Global $g_iCount Global $g_iIndex While 1 ; Loop forever $g_hWnd = WinGetHandle('AmiBroker') ; Get AmiBroker window handle If IsHWnd($g_hWnd) = 1 Then ; Check the window handle is valid If WinActive($g_hWnd) = 0 Then ; Check if AmiBroker is NOT active WinActivate($g_hWnd) ; If it's NOT active, activate it WinWaitActive($g_hWnd, '', 5) ; Wait for the handle to become active EndIf $g_hListView = ControlGetHandle($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]') ; Get the ListView handle $g_iCount = (_GUICtrlListView_GetItemCount($g_hListView) - 1) ; Get the number of items in the ListView $g_iIndex = 0 _GUICtrlListView_SetItemSelected($g_hListView, -1, False) _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex) ControlFocus($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]') Do ; _GUICtrlListView_SetItemSelected($g_hListView, -1, False) ; Deselect all items ; _GUICtrlListView_ClickItem($g_hListView, $g_iIndex, 'Left', False, 2, 0) ; Double click the ListView Item ; _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex) _GUICtrlListView_EnsureVisible($g_hListView, $g_iIndex) ; Scrolls the ListView to the given index - which we're increasing by one below ControlSend($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]', '{DOWN}') $g_iIndex += 1 Sleep(2000) ; Wait 2000ms (2 seconds) Until $g_iIndex > $g_iCount ; Loop until we've reached the end of the ListView _GUICtrlListView_EnsureVisible($g_hListView, 0) ; Once we've reached the end of the ListView above, move back to the top of the ListView Sleep(15000) ; Wait 15000ms (15 seconds) - once we've waited, the While loop will restart EndIf WEnd It may have stopped working as expected because the window handle was lost when the computer slept. The above script will get the window handle every 15 second loop, rather than once on startup. Also, it'll focus the ListView before entering the loop to scroll down it. I'm not sure if that'll help though as the window may need to be active. Edited June 30, 2021 by Luke94 Spelling
LearningEW Posted June 30, 2021 Author Posted June 30, 2021 Pls note all scripts have stopped working ....have restarted the system still not working. This had happed today morning also but after some time suddenly started working.
Luke94 Posted June 30, 2021 Posted June 30, 2021 25 minutes ago, LearningEW said: Pls note all scripts have stopped working ....have restarted the system still not working. This had happed today morning also but after some time suddenly started working. Were you running the script in SciTE Editor? Do you have an error/exit code?
LearningEW Posted June 30, 2021 Author Posted June 30, 2021 I past code shared here to the SciTE Editor, save it and then run script
Luke94 Posted June 30, 2021 Posted June 30, 2021 When the script stopped working, SciTE Editor should have shown an error or an exit code. Unless the script was still running but not functioning properly?
LearningEW Posted June 30, 2021 Author Posted June 30, 2021 I put this AutoItSetOption("TrayIconDebug", 1) as sometimes the scripts stops working. And when i see on the Autoit tray icon it shows line 32 sleep(15000)
Luke94 Posted June 30, 2021 Posted June 30, 2021 I assume that's telling you the current line been executed. The script waits for 15 seconds once it reaches the end of the ListView. The fact that the TrayIcon is still there tells me the script was still running. I'm guessing like I said before, the window handle is lost/changed when the computer sleeps. The latest script I posted should avoid that - however I'm sure you'll run into more problems if the computer sleeps. Can you not prevent the computer from sleeping?
LearningEW Posted June 30, 2021 Author Posted June 30, 2021 Computer sleeping can be stopped. But this script is also not working. Every few seconds its bringing Amibroker to foreground that's it. No stock/chart selection or scrolling. All scripts have stopped. I will send the Autoit window info again...has anything changed? on scroll bar
Luke94 Posted June 30, 2021 Posted June 30, 2021 My bad, I moved all the outer code inside the While loop. Try this: expandcollapse popup#include <GuiListView.au3> Global $g_hWnd Global $g_hListView Global $g_iCount Global $g_iIndex $g_hWnd = WinGetHandle('AmiBroker') ; Get AmiBroker window handle If IsHWnd($g_hWnd) = 1 Then ; Check the window handle is valid If WinActive($g_hWnd) = 0 Then ; Check if AmiBroker is NOT active WinActivate($g_hWnd) ; If it's NOT active, activate it WinWaitActive($g_hWnd, '', 5) ; Wait for the handle to become active EndIf While 1 ; Loop forever If IsHWnd($g_hWnd) = 1 Then $g_hListView = ControlGetHandle($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]') ; Get the ListView handle $g_iCount = (_GUICtrlListView_GetItemCount($g_hListView) - 1) ; Get the number of items in the ListView $g_iIndex = 0 _GUICtrlListView_SetItemSelected($g_hListView, -1, False) _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex) Do ; _GUICtrlListView_SetItemSelected($g_hListView, -1, False) ; Deselect all items ; _GUICtrlListView_ClickItem($g_hListView, $g_iIndex, 'Left', False, 2, 0) ; Double click the ListView Item ; _GUICtrlListView_SetItemSelected($g_hListView, $g_iIndex) _GUICtrlListView_EnsureVisible($g_hListView, $g_iIndex) ; Scrolls the ListView to the given index - which we're increasing by one below ControlSend($g_hWnd, '', '[CLASS:SysListView32; INSTANCE:5]', '{DOWN}') $g_iIndex += 1 Sleep(2000) ; Wait 2000ms (2 seconds) Until $g_iIndex > $g_iCount ; Loop until we've reached the end of the ListView _GUICtrlListView_EnsureVisible($g_hListView, 0) ; Once we've reached the end of the ListView above, move back to the top of the ListView Sleep(15000) ; Wait 15000ms (15 seconds) - once we've waited, the While loop will restart Else $g_hWnd = WinGetHandle('AmiBroker') Sleep(1000) ; Wait 1000ms EndIf WEnd EndIf It'll check the AmiBroker window handle is valid on each loop and if it isn't it'll try and obtain it again.
LearningEW Posted June 30, 2021 Author Posted June 30, 2021 Two things 1) [CLASS:SysListView32; INSTANCE:5]') here if i change to 1 then it selects and scrolls , if i keep 5 then it doesnt slect and scroll. Pls see the new Autoinfo shared it shows instance as 1 instead of 5 yesterday. 2) with [CLASS:SysListView32; INSTANCE:1] same issue that after it has reached the last stock then it moves to 1st stocks and scrolls but without selecting them
Luke94 Posted June 30, 2021 Posted June 30, 2021 Try changing all occurrences of that line to: '[CLASS:SysListView32; ID:903]' The Instance changes but ID remains the same. See if that works. When the ListView reaches the last stop and returns to the first, then scrolls without selecting them - Does that only happen when AmiBroker is in the background? Try running the script with AmiBroker active and leave it active, see if it does what it's supposed to.
LearningEW Posted June 30, 2021 Author Posted June 30, 2021 Even if amibroker is active it just scrolls the list without selecting. When the script is started that time also have to click on the 1st stock name otherwise it just scrolls.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now