Can sorting by % be scripted?

Get help with using AutoHotkey and its commands and hotkeys
torontob
Posts: 7
Joined: 25 Nov 2020, 21:27

Can sorting by % be scripted?

25 Nov 2020, 21:30

1- I have a stock broker which has a window like picture posted below that lists stocks, their prices, and percentage increase or decrease (CHANGE % column in picture). I would like AutoHotkey to sort those in ascending or descending order when I command it to or continuously as they change. Is this possible? If yes, how?

2- I only want a specific certain number of these stocks to be sorted and rest to be left alone. Is that also possible?

In image below you see I can sort each row by drag and drop using mouse.

*I am new to AutoHotkey so please detail your answer and steps.

Image

Thanks,
Last edited by gregster on 25 Nov 2020, 23:20, edited 1 time in total.
Reason: Topic moved to 'Ask For Help'; Image fixed.
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: Can sorting by % be scripted?

25 Nov 2020, 23:28

Are you referring to a formatted text file, or just an image that contains numbers?
User avatar
tank
Posts: 2855
Joined: 28 Sep 2013, 22:15
Facebook: charlie.simmons.7334
Google: ttnnkkrr
GitHub: ttnnkkrr
Location: Irving TX
Contact:

Re: Can sorting by % be scripted?

26 Nov 2020, 02:49

yea we really need to understand the interface that is being sorted.

what methods exist to read the value? can they ne viewed with the spy? is ot a web page? which browser?
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank :thumbup:
torontob
Posts: 7
Joined: 25 Nov 2020, 21:27

Re: Can sorting by % be scripted?

30 Nov 2020, 09:35

mikeyww wrote:
25 Nov 2020, 23:28
Are you referring to a formatted text file, or just an image that contains numbers?
Thanks for the reply.

This is a live stocks monitoring window from a broker called Interactive Brokers. It is not a static image. This is a live window that keeps updating prices. I believe the program is programmed with Java but I don't want to get into it's API (which also doesn't allow me to manipulate this page anyway) and rather go with Autohotkey to arrange things on screen for me.

Imagine the CHANGE % and LAST column continuously (every minute or so) updating. I would like to have a hotkey that can arrange them whenever I feel like.

Autohotkey can continuously re-sort them or just do when I command it. I would like to have both features.

Thanks,
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: Can sorting by % be scripted?

30 Nov 2020, 09:58

If you search the forum, you can find COM browser calls and also the Chrome.ahk library, which has browser tools. After you get the text from the page, the rest should be easy. Sorry I'm not more helpful; I don't use Chrome.ahk.
gregster
Posts: 5784
Joined: 30 Sep 2013, 06:48

Re: Can sorting by % be scripted?

30 Nov 2020, 10:08

As I understand it, it's a Java app, not Javascript in a browser. Which is not great - and Chrome.ahk can't help. Perhaps the Java Access Bridge could help... but I would rather go the API way: get the data via the API and build a custom GUI with AHK (of course that will take some effort).
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: Can sorting by % be scripted?

30 Nov 2020, 10:12

Thank you, @gregster! Great points.
torontob
Posts: 7
Joined: 25 Nov 2020, 21:27

Re: Can sorting by % be scripted?

30 Nov 2020, 15:43

gregster wrote:
30 Nov 2020, 10:08
As I understand it, it's a Java app, not Javascript in a browser. Which is not great - and Chrome.ahk can't help. Perhaps the Java Access Bridge could help... but I would rather go the API way: get the data via the API and build a custom GUI with AHK (of course that will take some effort).
You are correct. This is a Java Windows OS application and not Java Script so Chrome is out of the picture. I do have plans for API but that is a separate program and I like this Window so rather not recreate it. But I do hear what you are saying and what I get it is that one has to put a lot of effect into Autohotkey which may not be worth it and so do the API - is that what you were trying to say?

I really wished Autohotkey or another similar program can do sorting with a little bit of logic. End of the day this window is static in size and location so a mouse moving around should be easily able to move things except for it should also be smart and read the screen while it moves them so it can decide where to move. Sort of put all the values in an array and sort them. Autohotkey is not a good candidate for this?

Thanks,
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: Can sorting by % be scripted?

30 Nov 2020, 17:14

I think you want a method to get the underlying text, rather than reading graphical pixels on the screen. It is possible to read the pixels, but that would seem to be the "long way around" this issue.
torontob
Posts: 7
Joined: 25 Nov 2020, 21:27

Re: Can sorting by % be scripted?

30 Nov 2020, 23:18

mikeyww wrote:
30 Nov 2020, 17:14
I think you want a method to get the underlying text, rather than reading graphical pixels on the screen. It is possible to read the pixels, but that would seem to be the "long way around" this issue.
I am new to Autohotkey and still reading on it but I feel like it might be the tool I need.

1- Is there any OCR engine built in or can be called for reading screen image? (Maybe I can hotkey screenshot first)
2- All the values on the screen can be copied to clipboard so maybe click on each row and press Ctrl + C and save it to an array for sorting and once sorting is done then move each row to respective column?

I think my map #2 above is the way to go with this to do it quickly. If Autohotkey is not capable of that, what is it capable of?

Thanks,
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: Can sorting by % be scripted?

30 Nov 2020, 23:31

Well, sure, any of that could work if you prefer it. A few different OCR scripts have been written. Vis2 works nicely, though I don't know how it would perform on a table of text with many rows. You could try it.

Yes, if you can get text to the clipboard, then you can rearrange it, Sort it, etc. to meet your needs. The kinds of issues will be things like whether the table always appears in exactly the same position, has exactly the same number of rows, with the same row heights and widths, waiting for all of the clicks to happen, not touching the mouse or keyboard during that time, etc.
torontob
Posts: 7
Joined: 25 Nov 2020, 21:27

Re: Can sorting by % be scripted?

01 Dec 2020, 09:42

mikeyww wrote:
30 Nov 2020, 23:31
Well, sure, any of that could work if you prefer it. A few different OCR scripts have been written. Vis2 works nicely, though I don't know how it would perform on a table of text with many rows. You could try it.

Yes, if you can get text to the clipboard, then you can rearrange it, Sort it, etc. to meet your needs. The kinds of issues will be things like whether the table always appears in exactly the same position, has exactly the same number of rows, with the same row heights and widths, waiting for all of the clicks to happen, not touching the mouse or keyboard during that time, etc.
Thank you for bringing up the issues. I can say YES to all.
- I have multiple monitors but it will always be on same monitor and maximized so same place too.
- Has exact same number of rows or at least the bunch that I posted won't move.
- Height weight won't change.
- I can wait for all clicks BUT I am assuming autohotkey can click on 50 items + Ctrl+C them and Ctrl+V within a second. Isn't that correct? I understand it moves the mouse but should be faster than human - correct?
- I don't need to touch anything during that time. But would be good to have a way around it if you know 😅 as a bonus.

Now, that I have answered above, I don't like OCR. Can you please shed some light on how the sorting process may work in rearranging in clipboard?
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: Can sorting by % be scripted?

01 Dec 2020, 10:13

Sure.

First, I am doubtful that you could get 50 items in one second-- not because of AHK but because of Windows. My experience with Windows is that it cannot handle clipboard changes that quickly. At least, you might be pushing the limit and perhaps could squeeze in just 50 in one second. Worth a try, I suppose.

Are you able to select all text at once and copy to clipboard? It should be straightforward to parse at that point. That would save you from the 50 clicks.

More generally: see the link to "Sort" that I provided above. I think you would parse the text so that you have "rows" of information, and then sort the rows by a certain column, or have the column of interest as the first one.
torontob
Posts: 7
Joined: 25 Nov 2020, 21:27

Re: Can sorting by % be scripted?

01 Dec 2020, 11:11

mikeyww wrote:
01 Dec 2020, 10:13
Sure.

First, I am doubtful that you could get 50 items in one second-- not because of AHK but because of Windows. My experience with Windows is that it cannot handle clipboard changes that quickly. At least, you might be pushing the limit and perhaps could squeeze in just 50 in one second. Worth a try, I suppose.

Are you able to select all text at once and copy to clipboard? It should be straightforward to parse at that point. That would save you from the 50 clicks.

More generally: see the link to "Sort" that I provided above. I think you would parse the text so that you have "rows" of information, and then sort the rows by a certain column, or have the column of interest as the first one.
I understand what you mean about Window capabilities or rather inculpabilities. It is not possible to copy all at once. I can only select with mouse and do Ctrl + C or right click and press Copy. The Ctrl + C method will be faster.

Here is what I udnerstand how AHK can help:
1- It can select the row and press Ctrl + C
2- Then open notepad and Ctrl + V it there (isn't there internal memory to AHK so notepad or such is not used for sake of time?).
3- Use the Sort function of AHK to sort it: https://www.autohotkey.com/docs/commands/Sort.htm
4- Now, use the sorted list as a guide to go back to the window and sort the position of each row by drag and dropping it up or down the list

Can you please tell me if I am missing anything and if not, what tools/functions do I need to get to get #4 running. I see this is getting a bit complex already. I wish AHK could have a recorder so it could trace my steps and then do the same thing over and over for me. Is that possible? (if that is not being lazy then what is :clap:)
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: Can sorting by % be scripted?

01 Dec 2020, 11:28

There is Pulover Macro Recorder. I never tried it, but it seems to be popular. I think you really just need the screen coordinates of each row, and then you are set; that can be accomplished without a recorder by using Window Spy.

I wouldn't bother with Notepad. Just use variables in AHK. Sort acts on a variable anyway.

Instead of rearranging your screen widget, you could display your own GUI with the new information (just an option).
torontob
Posts: 7
Joined: 25 Nov 2020, 21:27

Re: Can sorting by % be scripted?

01 Dec 2020, 15:37

Thanks for all the help you are providing.
mikeyww wrote:
01 Dec 2020, 11:28
There is Pulover Macro Recorder. I never tried it, but it seems to be popular. I think you really just need the screen coordinates of each row, and then you are set; that can be accomplished without a recorder by using Window Spy.
I take it "Windows Spy" is a feature within AHK. And yes, I should have the co-ordinates easily.

mikeyww wrote:
01 Dec 2020, 11:28
I wouldn't bother with Notepad. Just use variables in AHK. Sort acts on a variable anyway.
OK, I will look at Sort function. I hope it's not intensive programming to the point that I would just be like I wish I went the API way.
mikeyww wrote:
01 Dec 2020, 11:28
Instead of rearranging your screen widget, you could display your own GUI with the new information (just an option).
What you said here is interesting. I don't think I want my own screen because then it will be another screen and I have to have another monitor. But not having seen AHK made screens I can't say for sure as I might fall in like with them.

For my #4 (previous post), once things are sorted, AHK can take instructions from sorted list and go back to the same window and then do a drag and drop by knowing the row number? (so my array would assign a number to each row?)

Thanks,
User avatar
mikeyww
Posts: 5104
Joined: 09 Sep 2014, 18:38

Re: Can sorting by % be scripted?

01 Dec 2020, 17:33

Sure, you can assign coordinates to each row. The coordinates are also likely some math function like y=5*row+50.

Sort is a command rather than a function.

Yes, Window Spy shows you coordinates, information about controls, and some other things. You can run it with the command below.

Code: Select all

Run, % StrReplace(A_AhkPath, "utoHotkey.", "U3_Spy.")

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], LeonAskin, wineguy, yoooooo and 63 guests