[오토핫키] Gui 색상을 랜덤하게 변경 시켜보자.

2024. 10. 1. 06:36오토핫키 오픈 스크립트

 

 

오토핫키 Gui 색상을 랜덤하게 바꿔보자.

 

이 스크립트는 클릭 이벤트가 발생 될 때마다, Gui 색상이 랜덤하게 변경됩니다.

 

어디 써먹을지는 모르겠지만, 심심해서 만들어 보았다.

 

 

 

; GUI 창 생성
Gui, +AlwaysOnTop +ToolWindow
Gui, Color, White  ; 초기 색상 설정
Gui, Show, w300 h200, Random Color GUI

; 최근 색상 기록을 위한 배열
recentColors := []

; GUI 클릭 시 색상 변경
OnMessage(WM_LBUTTONDOWN := 0x0201, "OnClick")

Return

OnClick(wParam, lParam, msg, hwnd) {
    color := RandomColor()
    Gui, Color, % "0x" . color
    Gui, Show, NA  ; 색상 변경 후 GUI를 다시 표시하여 업데이트
    
    ; 최근 색상 기록
    recentColors.Push(color)
    if (recentColors.MaxIndex() > 5) {
        recentColors.RemoveAt(1)  ; 최근 5개 색상만 유지
    }
    
    ; RGB 및 HSL 정보 표시
    rgb := "RGB: " . GetRGBValues(color)
    hsl := "HSL: " . RGBtoHSL(GetRGBValues(color))
    tooltipText := "Current Color: #" . color . "`n" . rgb . "`n" . hsl . "`nRecent Colors: " . RecentColorsText()
    ToolTip, %tooltipText%
    SetTimer, RemoveToolTip, -10000
}

RandomColor() {
    Random, r, 0, 255
    Random, g, 0, 255
    Random, b, 0, 255
    Return Format("{:02X}{:02X}{:02X}", r, g, b)
}

GetRGBValues(color) {
    r := "0x" . SubStr(color, 1, 2)
    g := "0x" . SubStr(color, 3, 2)
    b := "0x" . SubStr(color, 5, 2)
    Return % r . "," . g . "," . b
}

RGBtoHSL(rgb) {
    StringSplit, rgbArray, rgb, `,
    r := rgbArray1 / 255.0
    g := rgbArray2 / 255.0
    b := rgbArray3 / 255.0

    Max := Max(r, g, b)
    Min := Min(r, g, b)
    l := (Max + Min) / 2

    if (Max = Min) {
        s := 0
        h := 0 ; 무채색
    } else {
        d := Max - Min
        s := l > 0.5 ? d / (2 - Max - Min) : d / (Max + Min)
        if (Max = r)
            h := (g - b) / d + (g < b ? 6 : 0)
        else if (Max = g)
            h := (b - r) / d + 2
        else
            h := (r - g) / d + 4
        h /= 6
    }
    Return Format("{:.0f}, {:.0%}, {:.0%}", h * 360, s, l)
}

RecentColorsText() {
    global recentColors
    text := ""
    for index, color in recentColors
        text .= "#" . color . (index < recentColors.MaxIndex() ? ", " : "")
    Return text
}

RemoveToolTip:
ToolTip
Return

GuiClose:
ExitApp

 

 

 

 

프로그램 개발 의뢰 및 문의

검은망치 카카오톡오픈프로필 : https://open.kakao.com/o/sDUaoCNg

 

[오토핫키] 검은망치님의 오픈프로필

오토핫키 개발러

open.kakao.com