• 2013. 5. 15.

    by. 별머루

      
      

    오토핫키(Autohotkey) 강좌 #4 - Reload 함수

      

     

     

    <관련글>

    오토핫키(Autohotkey) 강좌 #1 - 오토핫키 설치

    오토핫키(Autohotkey) 강좌 #2 - 오토핫키의 메뉴 설명

    오토핫키(Autohotkey) 강좌 #3 - Return 함수

     

    이번 포스팅에선 오토핫키의 Reload 함수에 대해 알아보겠습니다.

    Reload 함수는 오토핫키를 사용하면서 거의 필수 불가결 하게 사용하는 함수 입니다

    사이트의 레퍼런스 내용을 한번 볼까요??

     

    Replaces the currently running instance of the script with a new one.

    Reload

    This command is useful for scripts that are frequently changed. By assigning a hotkey to this command, you can easily restart the script after saving your changes in an editor.

    Any command-line parameters passed to the original script are not passed to the new instance. To pass such parameters, do not use Reload. Instead, use Run in conjunction with A_AhkPath and A_ScriptFullPath (and A_IsCompiled if the script is ever used in compiled form). Also, include the string /restart as the first parameter (i.e. after the name of the executable), which tells the program to use the same behavior as Reload. See also: command line switches and syntax.

    When the script restarts, it is launched in its original working directory (the one that was in effect when it was first launched). In other words, SetWorkingDir will not change the working directory that will be used for the new instance.

    If the script cannot be reloaded -- perhaps because it has a syntax error -- the original instance of the script will continue running. Therefore, the reload command should be followed by whatever actions you want taken in the event of a failure (such as a return to exit the current subroutine). To have the original instance detect the failure, follow this example:

    Reload
    Sleep 1000 ; If successful, the reload will close this instance during the Sleep, so the line below will never be reached.
    MsgBox, 4,, The script could not be reloaded. Would you like to open it for editing?
    IfMsgBox, Yes, Edit
    return

    Related

    Edit

    Example

    ^!r::Reload  ; Assign Ctrl-Alt-R as a hotkey to restart the script.

     

    레퍼런스는 항상 복잡해 보여요ㅠㅠ 하지만 전혀~ 복잡하지 않습니다.

    Reload 오토핫키에서 이 함수는 Re(다시)Load(불러오다), 즉 오토핫키의 스크립트를 다시 불러오라 란 뜻입니다.

    예제를 한번 해석해 볼까요?

     

    ^!r::Reload  ; Assign Ctrl-Alt-R as a hotkey to restart the script.

     

    좀더 쉽게 바꿔볼까요? 실제 사용 가능하게요

     

    F12::Reload ; F12 키를 누르면 스크립트 다시 불러온다.

     

    딱! 한줄 입니다. 한줄!! 이거 설명하기도 부끄럽네요.

    영어를 좀 읽을줄 아는 분은 뒤에 보이시죠?

    Ctrl+ALT+R 키를 누르면 오토핫키에 스크립트가 재시작 된다. 라고 적혀있네요.

     

    이런 간단한 함수를 왜 설명 하느냐?? 집중 합시다 집중!!

     

    힘들게 오토핫키를 편집기로 작성해서 저장을 합니다. (예를들어 F1키를 누르면 "안녕하세요!! 001" 메세지 박스를 출력했습니다. 여기서 욕심이 나서 "반갑습니다 001" 메세지 박스를 추가로 입력하고 저장했다고 가정하죠.) 저장 딱! 하고 F1 키를 설레는 마음으로 누르는 순간?

    오토핫키는 반응이 없을겁니다. 왜냐? 편집기에서 저장했는데 왜 안될까? 이유는 간단 합니다.

    오토핫키는 이미 "안녕하세요 001" 를 출력하고 실행대기중인 상태입니다. 즉 종료가 되지 않았다는거죠. 그상태에서 "반갑습니다001"를 추가 해도 저장만 됫을뿐 스크립트에선 아직 적용이 되지 않았다는 겁니다. 뭐.. 물론 오토핫키를 껏다 키면 적용이 되죠.

     

    하지만 이렇게 스크립트 한줄 두줄 추가할때마다 오토핫키를 껏다 키는 매우 불편한 동작을 반복하려는건 아니죠? Reload 함수가 빛이 나는 순간은 바로 지금입니다.

     

    만약에 여러분이 위의 예제를 스크립트에 넣어 놨다고 가정해볼게요. "반갑습니다 001" 메세지 박스를 스크립트에 추가하고 저장 후  간단하게 Ctrl+Alt+R 키를 눌러주시면 오토핫키에서 스크립트를 다시 불러 옵니다. 물론 오류가 났거나 오타가 있으면 이 과정에서 스크립트 오류를 마구 뿜어대죠.

     

    이해가 가시죠? 아주 간단한 스크립트 한줄 미리 추가해놓는 습관으로 어느때나 스크립트를 다시부르기가 가능해진겁니다.  Reload 함수는 자동차로 말하면 기어(미션) 같은 존재 라고 할 수 있죠.  운전석에 앉아 키 꼽고 시동 건다음 자 출발 ~~! 했는데 기어가 N 에 있다면? ㅎㅎ

     

    이번 4번째 강좌에서도 매우 간단한 함수인 Reload 함수를 알아봤습니다.  솔직히 이 함수가 왜 있는지 잘 모르셧던분!!! 댓글 다세욧!!ㅋㅋ

     

    포스팅을 마치면서 ~ !! 제 강좌를 보시는 분은 귀찮으시더라도 꼭 !! 꼬옥!! 예제를 오토핫키로 적용해서 한번씩 해보세요. 나중에 도움이 될 뿐더러 오토핫키 사용의 바른 습관을 처음부터 익힐수 있어요^^