A collection of small ahk functions

Post your working scripts, libraries and tools
Trubbleguy
Posts: 8
Joined: 11 Jul 2014, 03:00

Case (fixes names like o'donnel and McNamra)

21 May 2016, 01:55

I needed a way to make all my artist names correctly Upper/Lower case, in my file renaming and databases, so i put this together, I have used it in my Appointment book prog and others. maybe somebody can also make use of it, There is sample code built into the function header that is ignored when the function is called, but runs if you directly run the function from your editor.
Spoiler
User avatar
jNizM
Posts: 2451
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: A collection of small ahk functions

23 May 2016, 00:55

boiler wrote:I must be missing something, but how did you create the string "21EC2020-3AEA-4069-A2DD-08002B30309D"? Is there a function that is supposed to convert the "1866374240" to that? I'm sure I'm showing my ignorance on this subject.
It's just a random string I used as example for the function. RSHash creates a small numeric only hash.
MsgBox % RSHash("some_random_string_to_rshash_func")
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2451
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: A collection of small ahk functions

24 May 2016, 04:33

CRC32 (Cyclic redundancy check)

Source: (Implementation via AutoHotkey & via DllCalls)
CRC32.ahk (GitHub)

example:

Code: Select all

MsgBox % CRC32("The quick brown fox jumps over the lazy dog")
output:

Code: Select all

0x414fa339

Ref:
- Cyclic redundancy check (wiki)
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2451
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: A collection of small ahk functions

13 Jun 2016, 03:48

GetMacAddress (Get a list of computers MAC address.)

Source:
GetMacAddress.ahk (GitHub)

example:

Code: Select all

for k, v in GetMacAddress()
    MsgBox % v
output:

Code: Select all

01:23:45:67:89:ab

Ref:
- MAC address (wiki)
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
lmstearn
Posts: 211
Joined: 11 Aug 2016, 02:32
GitHub: lmstearn
Contact:

Re: A collection of small ahk functions

20 Aug 2016, 09:13

Useful collection!
just me wrote:This is getting unclear. What about a TOC in the first post?
There's a script to do that somewhere, but too large for this category!
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH
Helgef
Posts: 3892
Joined: 17 Jul 2016, 01:02
Contact:

Re: A collection of small ahk functions

09 Sep 2016, 02:14

jNizM wrote:Minimum
Find the minimum of 2 vars

Code: Select all

min(x, y)
{
    return y ^ ((x ^ y) & -(x < y))
}

MsgBox % min(27, 64)    ; ==> 27
======================================================================================

Maximum
Find the maximum of 2 vars

Code: Select all

max(x, y)
{
    return x ^ ((x ^ y) & -(x < y))
}

MsgBox % max(27, 64)    ; ==> 64
That only works for integers. This works for doubles too

Code: Select all

min(x,y)
{
	return (x<y)*x+(y<=x)*y
}

max(x,y)
{
	return (x>y)*x+(y>=x)*y
}
User avatar
jNizM
Posts: 2451
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: A collection of small ahk functions

12 Sep 2016, 01:18

HasVal (for Simple Arrays)
Checks if a value exists in an array (similar to HasKey)

FoundPos := HasVal(Haystack, Needle)

Code: Select all

HasVal(haystack, needle) {
    for index, value in haystack
        if (value = needle)
            return index
    if !(IsObject(haystack))
        throw Exception("Bad haystack!", -1, haystack)
    return 0
}
Examples

Code: Select all

arr := ["a", "b", "", "d"]
MsgBox % HasVal(arr, "a") "`n"    ; ==> 1
       . HasVal(arr, "c") "`n"    ; ==> 0
	   . HasVal(arr, "d")         ; ==> 4

Code: Select all

arr := {keyA: "A", keyB: "B"}
MsgBox % HasVal(arr, "B") "`n"    ; ==> keyB
       . HasVal(arr, "C")         ; ==> 0

Code: Select all

arr := {keyA: "A", 1: 0, keyC: "C"}
MsgBox % HasVal(arr, 0)   "`n"    ; ==> 1
       . HasVal(arr, "C") "`n"    ; ==> keyC

Code: Select all

str := "A"
MsgBox % HasVal(str, "A")         ; ==> fails -1
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2451
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: A collection of small ahk functions

10 Oct 2016, 02:40

GetDnsAddress (Get a list of DNS servers used by the local computer.)

Source:
GetDnsAddress.ahk (GitHub)

example:

Code: Select all

for k, v in GetDnsAddress()
    MsgBox % v
output:

Code: Select all

8.8.8.8
8.8.4.4

Ref:
- Domain Name System (wiki)
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
JoeWinograd
Posts: 1249
Joined: 10 Feb 2014, 20:00

Re: A collection of small ahk functions

23 Jan 2017, 03:20

Hi jNizM,
Very nice job! Thanks for putting this together. Two minor typos that you may want to fix: in the title, "usefull" should be "useful"; in the TOC's InArr entry, "InSrt" should be "InStr". Regards, Joe
User avatar
jNizM
Posts: 2451
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: A collection of small ahk functions

23 Jan 2017, 03:30

merci & fixed
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2451
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: A collection of small ahk functions

27 Jan 2017, 05:54

RefreshPolicy (Causes policy to be applied immediately on the computer like gpupdate does)

Source:
RefreshPolicy.ahk (GitHub)

example:

Code: Select all

RefreshPolicy(1, 1)    ; -> refresh the computer policy with force flag
RefreshPolicy(0, 1)    ; -> refresh the user     policy with force flag

Ref:
- RefreshPolicy function (msdn)
- RefreshPolicyEx function (msdn)
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2451
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: A collection of small ahk functions

17 Feb 2017, 09:36

UpdateScript
Update running (.ahk) script in realtime (~ 500-1000 ms) if you change something in the script

Code: Select all

UpdateScript()
{
    if ((attrb := DllCall("GetFileAttributes", "str", A_ScriptFullPath)) = 0x20) {
        DllCall("SetFileAttributes", "str", A_ScriptFullPath, "uint", attrb &= ~0x20)
        TrayTip,, % "Script has been updated."
        sleep 1000
        reload
    }
}
Example

Code: Select all

; GLOBAL SETTINGS ===============================================================================================================

#NoEnv
#SingleInstance Force
#Persistent

SetBatchLines -1

; CHECK UPDATE ==================================================================================================================

SetTimer, UpdateScript, 500
return

; SCRIPT ========================================================================================================================

; your script here

; FUNCTIONS =====================================================================================================================

UpdateScript()
{
    if ((attrb := DllCall("GetFileAttributes", "str", A_ScriptFullPath)) = 0x20) {
        DllCall("SetFileAttributes", "str", A_ScriptFullPath, "uint", attrb &= ~0x20)
        TrayTip,, % "Script has been updated."
        sleep 1000
        reload
    }
}

Ref:
Refresh program to detect code change
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
Relayer
Posts: 125
Joined: 30 Sep 2013, 13:09
Location: Delaware, USA

Re: A collection of small ahk functions

17 Feb 2017, 11:51

jNizM,

So I assume it will not reload a script that had a sub-component change like a library or an included file? Seems that one would need to pass the function an argument containing the names of all used files but that is not easy to keep up to date.

Relayer
User avatar
jNizM
Posts: 2451
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: A collection of small ahk functions

20 Feb 2017, 08:28

@Relayer,

would be possible with a build-in fuction like A_IncludeFiles who returns an array with all #Include's files.

Maybe something for @lexikos if its possible and he is interested enough ;)
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2451
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: A collection of small ahk functions

03 Mar 2017, 03:23

WM_DEVICECHANGE
Notifies an application of a change to the hardware configuration of a device or the computer. (Removal devices like USB)

Source:
WM_DEVICECHANGE.ahk (GitHub)

Example
See source

Ref:
WM_DEVICECHANGE message (msdn)
DBT_DEVICEARRIVAL event (msdn)
DBT_DEVICEREMOVECOMPLETE event (msdn)
DEV_BROADCAST_HDR structure (msdn)
DEV_BROADCAST_VOLUME structure (msdn)
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2451
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: A collection of small ahk functions

22 Aug 2017, 05:36

Base64 (String)
Encode a string to base64 format & decode from base64 format to a string (Unicode / UTF-8)

Source:
base64.ahk (GitHub)

Example
See source

Ref:
Base64 (wiki)
CryptBinaryToString function (msdn)
CryptStringToBinary function (msdn)
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Sam_ and 38 guests