         }
     }
     
-    config(size, rate, sleep_ms)
+    config_capture(size, rate, u_or_d, capture_minutes)
     {
-        Send, !p  ; panel
-        Sleep, %sleep_ms%
-        Send, s   ; scan?
-        Sleep, %sleep_ms%
+        ; Do NOT "Show all items" in "Scan Controls".
+        ; Activate "Scan size".
         
-        ;; throw if "Scan size" not activated
+        ; throw if u_or_d not in ["u", "d"]
         
-        SendInput, %size%
-        Sleep, %sleep_ms%
-        Loop, 4
-        {
-            SendInput, {Down}
-            Sleep, %sleep_ms%
-        }
-        ;; throw if not addapted
-        SendInput, %rate%
-        Loop, 4
-        {
-            SendInput, {Up}
-            Sleep, %sleep_ms%
-        }
+        SetKeyDelay, 500
+        WinActivate, NanoScope Control
+        
+        Send !ps  ; Panels -> Scan
+        Send % size
+        
+        Send {Down}{Down}{Down}{Down}%rate%
+        Send {Up}{Up}{Up}{Up}
+        
+        Send ^c  ; Capture
+        Send !f%u_or_d%  ; Frame -> Up or Down
+        
+        sleep_minute(capture_minutes)
     }
         
-    capture(u_or_d)
-    {
-        ;; throw if u_or_d not in ["u", "d"]
-        Send, ^c  ; capture
-        Sleep, %sleep_ms%
-        Send, !f  ; frame
-        Sleep, %sleep_ms%
-        SendInput, %u_or_d%
-        ;; throw if not started
-        Sleep, %sleep_ms%
-    }
 
     static dbg_cnt = 0
     dbg()


execute()
{
    AFM.export_jpg(1, "d:\ashihara\img", 178, 207)
}



#Include range.ahk

; Right click "H" mark in the taskbar to stop.
;~ SetKeyDelay, 500

Space & e::ExitApp
Space & r::Reload
