Small AHK v2 functions

Post your working scripts, libraries and tools.
User avatar
xypha
Posts: 24
Joined: 24 Apr 2020, 04:14

Small AHK v2 functions

20 Dec 2023, 04:08

  • Tray Icon - change script tray icon (which also changes the default icon in a script's error windows, msgboxes and GUI title icon).
  • HasVal Function - Check if value is already in an array and retrieve it's Index if present.
This code is old.
Updates will be posted here on GitHub.

Code: Select all

#Requires AutoHotkey v2.0

; Auto-execute
; Add to the top of your script

;  = Tray Icon

I_Icon := A_ScriptDir "\icons\1-512.ico"
; Icon source: https://www.iconsdb.com/caribbean-blue-icons/1-icon.html     ; CC License
; I like to number scripts 1, 2, 3... and link the scripts to numpad shortcuts for easy editing
If FileExist(I_Icon)
    TraySetIcon I_Icon

Return ; ends autoexecute

;  = HasVal Function
; Modifed from https://www.autohotkey.com/boards/viewtopic.php?p=109173#p109173
; not for associative arrays

HasVal(haystack, needle) {
    ; if !(IsObject(haystack)) || (haystack.Length() = 0)
    ;   return -1
    ; optimise above code to your needs after reading lexikos' comment here - https://www.autohotkey.com/boards/viewtopic.php?p=110388#p110388
    for index, value in haystack
        if (value == needle) ; case-sensitive
            return index
    return 0
}
Last edited by xypha on 26 Dec 2023, 13:07, edited 5 times in total.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Small AHK v2 functions

20 Dec 2023, 06:30

I do not understand.
V2 has already default min and max functions, who accept both parameters or arrays.

Only the HasVal functions does not exist.
User avatar
xypha
Posts: 24
Joined: 24 Apr 2020, 04:14

Re: Small AHK v2 functions

20 Dec 2023, 11:22

@AHK_user
It does. Huh, I didn't know. I used these ones in my AHK v1 script for a long time. Thanks for pointing it out.

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: Marium0505, Smile_ and 38 guests