• 2013. 6. 10.

    by. 별머루

      
      

    오토핫키(Autohotkey) 강좌 #5 - Pause 함수

      

     

    <관련글>

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

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

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

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

     

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

    Pause 함수는 오토핫키를 사용하시면서 많이 사용하게 될 함수 입니다. 사용법은 매우 간단하지만 사용빈도가 높은 만큼 확실히 알고 넘어가는게 좋은 함수입니다.

    Pause 함수의 레퍼런스를 한번 볼까요?

     

     

    Pauses the script's current thread.

    #p::Pause ; Pressing Win+P once will pause the script. Pressing it again will unpause.
    Pause [, On|Off|Toggle, OperateOnUnderlyingThread?]

    Parameters

    On|Off|Toggle

    If blank or omitted, it defaults to Toggle. Otherwise, specify one of the following words:

    Toggle: Pauses the current thread unless the thread beneath it is paused, in which case the underlying thread is unpaused.

    On: Pauses the current thread.

    Off: If the thread beneath the current thread is paused, it will be in an unpaused state when resumed. Otherwise, the command has no effect.

    OperateOnUnderlyingThread?

    This parameter is ignored for "Pause Off" because that always operates on the underlying thread. For the others, it is ignored unless Pause is being turned on (including via Toggle).

    Specify one of the following numbers:

    0 (or omitted): The command pauses the current thread; that is, the one now running the Pause command.

    1: The command marks the thread beneath the current thread as paused so that when it resumes, it will finish the command it was running (if any) and then enter a paused state. If there is no thread beneath the current thread, the script itself is paused, which prevents timers from running (this effect is the same as having used the menu item "Pause Script" while the script has no threads).

    Note: A_IsPaused contains the pause state of the underlying thread.

    Remarks

    Unlike Suspend -- which disables hotkeys and hotstrings -- turning on pause will freeze the current thread. As a side-effect, any interrupted threads beneath it will lie dormant.

    Whenever any thread is paused, timers will not run. By contrast, explicitly launched threads such as hotkeys and menu items can still be launched; but when their threads finish, the underlying thread will still be paused. In other words, each thread can be paused independently of the others.

    The color of the tray icon changes from green to red whenever the script's current thread is in a paused state. This color change can be avoided by freezing the icon, which is achieved by specifying 1 for the last parameter of the Menu command. For example:
    Menu, Tray, Icon, C:\My Icon.ico, , 1

    To disable timers without pausing the script, use "Thread, NoTimers".

    The Pause command is similar in function to the built-in menu item "Pause Script".

    A script is always halted (though not officially paused) while it is displaying any kind of menu (tray menu, menu bar, GUI context menu, etc.)

    Related

    Suspend, Menu, ExitApp, Threads, SetTimer

    Examples

    Pause::Pause  ; Assign the toggle-pause function to the "pause" key...
    #p::Pause  ; ... or assign it to Win+p or some other hotkey

     

    역시나 레퍼런스는 복잡 @_@; 물론! 전혀 사용하는데 복잡하진 않습니다. 설명이 어려울 뿐이죠^^;

    Pause 함수는 말 그대로 "잠시 멈추다" 라는 뜻이라고 보시면 됩니다.

     

    자 그럼 예제를 한번 볼까요?

     

    Pause::Pause  ; Assign the toggle-pause function to the "pause" key...
    #p::Pause  ; ... or assign it to Win+p or some other hotkey

     

    영어를 좀 읽을줄 아시는분은 이미 "아~" 하셧을 겁니다. 하지만 좀더 쉽게 예제를 풀어볼게요!

     

    F4::Pause ; F4 키를 누르면 Pause(잠시 멈춘다) 한다.

     

    Reload 함수에 이어 Pause 함수도 딱 한줄 입니다. 즉 F4 키를 누르면 스크립트를 잠시 멈춘다. 인거죠. 이게 왜 필요한건지 이해가 안가시는분도 있겠지만. 간단히 한번 하고 끝나는 스크립트 에서도 이 Pause 함수는 유용하게 쓰입니다.

    예를들어 볼까요? "1부터 100억 까지의 숫자중 랜덤 연산하여 가장 많이 노출이 되는 수를 찾아라(로또 비슷한) 스크립트를 오토핫키로 작성 - > 실행 하였습니다. 물론 컴퓨터의 연산 능력은 상상을 초월 하지만.. 만약에 1초에 한번의 연산만 가능하다. 라고 정해두었으면 100억까지의 연산 시간은 100억초가 되겠네요. 하지만 그 중간에 스크립트를 Reload 하거나 Exitapp(이건 차후에 설명) 하면 그동안 연산 되었던 기록은 다 날아가게 되죠. 즉 스크립트가 강제로 종료되거나 초기화 된다는 겁니다.

     

    이런 어처구니 없는 사태를 미연에 방지할수 있는 함수가 바로 Pause 함수 입니다. 즉 ! 잠깐 멈춰!! 라고 오토핫키에 명령을 내려주는거죠. 잠깐 멈춘후에 다시 Pause 함수를 불러주면 처음부터 다시 시작할 필요없이 작업중이던 스크립트를 그대로 이어가는 거라고 생각하시면 됩니다.

     

    이상  오토핫키의 Pause 함수 설명을 마치겠습니다. 아직까진 너무 쉬운 함수들만 설명 하고 있는거 같네요. 하지만 오토핫키도 어느 순간 부터는 난이도가 확실히 올라가게 됩니다. 그러니 긴장 풀지 마시고 다음 포스팅에서 보겠습니다 ^^