commands as functions (AHK v2 functions for AHK v1)

Discuss the future of the AutoHotkey language
User avatar
jeeswg
Posts: 4273
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

21 Sep 2017, 17:17

Download: case-corrected 'URLDownloadToFile' to 'UrlDownloadToFile'
InputBox: first two parameters swapped
MsgBox: final parameter removed

Please notify of any issues.

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



[EDIT:] The MsgBox function needs to be corrected from:
Press OK to continue
to:
Press OK to continue.
The dot needs to be added. I will add this in the next release.

[EDIT:] The SendMessage and PostMessage functions need updating, they will be added to the next release.

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

Last edited by jeeswg on 14 Nov 2017, 17:25, edited 1 time in total.
iseahound
Posts: 222
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: commands as functions (AHK v2 functions for AHK v1)

05 Nov 2017, 23:30

Can you release the above post separately? Your first post has 7 different code boxes, and none of them are even up to date.

This will be useful to many people.
User avatar
jeeswg
Posts: 4273
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

05 Nov 2017, 23:49

@iseahound: I've put a link to the latest version in the first post. Cheers.
User avatar
jeeswg
Posts: 4273
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

28 Jan 2018, 23:26

I've updated the library, here are some summary notes.
- Added. I've added CaretGetPos, TraySetIcon and WinGetClientPos.
- Removed. I've removed Menu.
- MinParams. By using Func objects, I retrieved the minimum number of parameters for each function in AHK v2, and each of these clone functions, and adjusted any functions in this library accordingly.
- ComboBox/ListBox. There are 3 ControlXXX functions in this library that check the control class name. I've made it so that they check that the class name contains a string, rather than matches it exactly, as I've seen varying class names, that still work with the ControlXXX functions.
- PostMessage/SendMessage. These two functions have changed significantly, in what they return, and how they set ErrorLevel. Although it will require manual script conversion to use them, particularly for SendMessage, they are far more useful in their new forms.
- SoundGet/SoundSet. I realised that these cloned functions weren't working on my PC. I changed the default value for DeviceNumber from 1 to blank in the library.
- [EDIT:] Corrected ControlSetStyle/ControlShow and FileAppend.

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


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

- [EDIT:] Auxiliary functions expansion pack first release. These make it easier/possible to write two-way compatible scripts/functions.

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


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

- [EDIT:] Modifications that will appear in the next release: CaretGetPos.
- Note: Custom CaretGetPos function based no:
convert coordinates between Client/Screen/Window modes - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=38472&p=177058#p177058

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

- [EDIT:] Additions that will appear in the next release: A_TrayMenu.ClickCount.

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

Last edited by jeeswg on 05 Mar 2018, 09:38, edited 3 times in total.
User avatar
jeeswg
Posts: 4273
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

13 Feb 2018, 00:35

- I've corrected ControlSetStyle and FileAppend. These are two important corrections so I've corrected the latest version of the script posted above directly, instead of waiting for the next full release.
- The issue with FileAppend was that it might have been using the wrong encoding e.g. ANSI instead of UTF-8/UTF-16. Btw be careful with file encodings generally in standard AutoHotkey, because you might specify an encoding, but AutoHotkey will overrule it (if the file already exists and has a byte order mark).
- I will be creating a large test script, to be run on both AHK v2, and on 'AHK v1+AHK v2 functions', to check that they are both giving the same results. I mention this in case anyone has already created such a script that I can compare it with.
- Note: always double-check when using these functions for the first time, and always double-check when using functions on important data, especially functions that relate to registry loops or modifying the registry.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: commands as functions (AHK v2 functions for AHK v1)

13 Feb 2018, 09:40

Thank you for reminding me about GetGUIThreadInfo() which set me on the right track.
However, this CaretGetPos() function as it is has a major flaw: it cannot retrieve the coordinates of the caret if the control isn't focused. And I specifically needed that in a script of mine.
So in order for it to be complete, I'd add a forcedHwnd parameter to it:

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


That way the user could direct the function to retrieve the caret position from a specific control by feeding it with that control's handle and by briefly setting focus to that control (and restoring it afterwards).

Also I'm not sure about the calculations you do between Client/Screen/Window. GetGUIThreadInfo() already returns client coordinates relative to the focused control. If the user wants precisely those coordinates - not relative to the main window - then he's in a bit of a trouble.
So I'd say in case the forcedHwnd parameter is present (and valid), the client coordinates should be returned as is, maybe even regardless of A_CoordModeCaret. Otherwise the user would have to recreate the whole function with the desired modifications and that would just be a waste of time.

There's also no return value. If for some reason any of the handles is invalid, there's no focused control or GetGuiThreadInfo() fails, the function should return False, otherwise it should return True - that should differentiate between success and failure when coordinates are identical on both input and output.
User avatar
jeeswg
Posts: 4273
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

13 Feb 2018, 15:59

- Thanks for your comments Drugwash.
- I've made a slight modification to my original JEE_CaretGetPos function, to allow specifying an hWnd, which you can find here:
convert coordinates between Client/Screen/Window modes - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=38472&p=200323#p200323
- If you want to, on that thread, you can propose an amended function that provides a return value.
- My JEE_CaretGetPos function does allow you to retrieve the original caret coordinates, although the AHK v2 CaretGetPos function (and my clone of it) does not.
- The main thing I want to know about, in this thread re. functions, is whenever one of the functions in this library gives different results to AHK v2 (apart from in any special circumstances which I have mentioned e.g. InputBox's hide character). If you want the AHK v2 functions themselves to be changed/improved, then that would have to go in the Wish List forum, or a custom function would have to be made like the one I've mentioned.
- Thanks for reminding me about return values. In this link it is mentioned that the return values need to be reviewed for various AHK v2 functions:
v2-thoughts
https://autohotkey.com/v2/v2-thoughts.htm
I will compare the return values for this library with the AHK v2 functions, when I produce my massive test script, to test all functions. One thing I'd hope for, in the AHK v2 functions, is to return an hWnd if WinWait/WinWaitActive are successful. Cheers.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: commands as functions (AHK v2 functions for AHK v1)

13 Feb 2018, 16:14

You're welcome.
Actually I don't care much about v2 since it's breaking too much away from the original AHK - just wanted to share my thoughts while I was here. Feel free to forward the ideas/observations I made above wherever appropriate if you feel they're worth mentioning. :)
lexikos
Posts: 5895
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: commands as functions (AHK v2 functions for AHK v1)

17 Feb 2018, 17:30

Drugwash wrote:it cannot retrieve the coordinates of the caret if the control isn't focused.
It cannot retrieve the coordinates of the caret if there is no caret. The control creates the caret when you focus it and destroys it when the control loses focus. What you are getting is not the position of the caret, but the position the caret would be in if the control was (still) focused.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: commands as functions (AHK v2 functions for AHK v1)

18 Feb 2018, 02:28

That is technically true, the other technique using EM_* messages retrieves the position of the selection in the (Rich)Edit control, not the position of the invisible/nonexistant caret. Nonetheless, that position may be of critical interest in certain scripts and I believe there should be this - let's call it "unorthodox" - possibility to retrieve it, for completeness sake.

This is all necessary because EM_POSFROMCHAR returns -1 when caret/selection is beyond last character and there's no other way to retrieve the actual caret position in pixels.
User avatar
jeeswg
Posts: 4273
Joined: 19 Dec 2016, 01:58
Location: UK

Re: commands as functions (AHK v2 functions for AHK v1)

29 Mar 2018, 00:30

Added. CallbackCreate, CallbackFree, A_TrayMenu.ClickCount.
Modified. CaretGetPos, MsgBox.
Modified. Return hWnd: WinWait, WinWaitActive (I've assumed that WinWait/WinWaitActive will return an hWnd in future).
Modified. Support numbers: DetectHiddenText, DetectHiddenWindows, ListLines, Pause, SetCapsLockState, SetNumLockState, SetScrollLockState, SetStoreCapsLockMode, Suspend.
Tidied. WinSetAlwaysOnTop.
Please notify of any issues re. CallbackCreate and CallbackFree.

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

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

Re: commands as functions (AHK v2 functions for AHK v1)

05 Apr 2018, 20:09

UPDATE. I've been running various tests on the library (details are in the post below), and have thus identified and resolved some issues.
Fixed (handle 1 and 0): BlockInput.
Fixed (return dec not hex): MouseGetPos.
Fixed (handle omitted parameters): InputBox, IniDelete, TrayTip.
Fixed: ControlDeleteItem, FileAppend, IniRead, MsgBox, RegDelete.

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