[오토핫키] 원하는 창에서만 매크로 작동시키기

2024. 9. 11. 02:48오토핫키 오픈 스크립트

안녕하세요 검은망치 입니다.

 

오토핫키를 사용해서 매크로를 사용하다보면 매크로가 작동중일때는 다른창을 못누를 때가 있습니다.

이걸 해결할 수 있는 간단한 프로그램을 짜봤습니다

 

이름하여 "원하는 창에서만 매크로 작동시키는 프로그램!!" 

 

 

 

메모장 파일에는 1a 를 입력하게, 네이버창에는 2b를 입력하게 설정해봤습니다.

 

아주 잘 작동되네요 ㅎㅎ

 

응용한다면 많은걸 할 수 있겠습니다.

 

특정창에서만 스크립트가 작동 (창다수등록).ahk
0.00MB

 

 

#Persistent
SetTitleMatchMode, 2

; 윈도우 제목과 입력 문자열을 저장할 배열
windows := []

Gui, Add, Text,, 윈도우 창 제목 (일부만 일치해도 됨)
Gui, Add, Edit, vWindowTitle w300 h25
Gui, Add, Text,, 입력할 키나 문자열을 입력하세요. (예: a, {Left}, {Right})
Gui, Add, Edit, vSendText w300 h25
Gui, Add, Button, gAddWindow, 추가
Gui, Add, Button, gEditWindow x+10, 수정
Gui, Add, Button, gDeleteWindow x+10, 삭제
Gui, Add, ListView, vWindowList x10 w300 h100, 윈도우 제목|입력 문자열
Gui, Add, Button, gStartLoop, 시작
Gui, Add, Button, gPauseLoop x+10, 일시정지
Gui, Add, Button, gExitApp x+10, 종료
Gui, Add, Text, x10, 시작: F10 | 일시정지: F11 | 종료: F12
Gui, Show,, 특정창에서만 스크립트가 작동

Return

AddWindow:
Gui, Submit, NoHide
if (WindowTitle != "" && SendText != "")
{
    ; ListView에 항목 추가
    LV_Add("", WindowTitle, SendText)
    
    ; 배열에 추가
    windows.Push({title: WindowTitle, text: SendText})
    
    ; 입력 필드 초기화
    GuiControl,, WindowTitle
    GuiControl,, SendText
}
else
{
    MsgBox, 48, 오류, 윈도우 제목과 입력 문자열을 모두 입력하세요.
}
Return

EditWindow:
selectedRow := LV_GetNext(0) ; Get selected row
if (selectedRow)
{
    ; 선택된 항목의 데이터를 가져옴
    LV_GetText(selectedTitle, selectedRow, 1)
    LV_GetText(selectedText, selectedRow, 2)
    
    ; 입력 필드에 표시
    GuiControl,, WindowTitle, %selectedTitle%
    GuiControl,, SendText, %selectedText%
    
    ; 배열에서 해당 항목 삭제
    windows.RemoveAt(selectedRow)
    
    ; ListView에서 항목 삭제
    LV_Delete(selectedRow)
}
else
{
    MsgBox, 48, 오류, 수정할 항목을 선택하세요.
}
Return

DeleteWindow:
selectedRow := LV_GetNext(0) ; Get selected row
if (selectedRow)
{
    ; 배열에서 해당 항목 삭제
    windows.RemoveAt(selectedRow)
    
    ; ListView에서 항목 삭제
    LV_Delete(selectedRow)
}
else
{
    MsgBox, 48, 오류, 삭제할 항목을 선택하세요.
}
Return

F10::
StartLoop:
if (LV_GetCount() = 0)
{
    MsgBox, 경고: 리스트박스에 항목이 없습니다. 추가 후 시작하세요.
    Return
}

Pause := false

Loop
{
    if (Pause)
    {
        Sleep, 100
        continue
    }

    ; 각 윈도우에 대해 입력 수행
    for index, window in windows
    {
        IfWinActive, % window.title
        {
            Send, % window.text
            Sleep, 100
        }
    }
    Sleep, 100
}

Return

F11::
PauseLoop:
Pause := !Pause
MsgBox, % Pause ? "일시정지되었습니다." : "재개되었습니다."
Return

F12::
ExitApp:
ExitApp

GuiClose:
ExitApp

 


검은망치 카카오톡 오픈채팅방 : https://open.kakao.com/o/sDUaoCNg

 

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

오토핫키 개발러

open.kakao.com