Hit Any Key to Continue
QUESTION: PV-WAVE had a nifty little program named HAK. It stood for Hit Any Key to Continue. It was really handy for temporarily interruping program execution until the user was ready to continue. Does such a thing exist in IDL?
![]()
ANSWER: No, but it is not hard to program. Here is one, appropriately named HAK, that Pardeep Pall and I came up with recently. It seems to do the job nicely.
PRO HAK, NoPrompt=noprompt
; Clear typeahead buffer before input
WHILE Get_KBRD(0) do junk=1
; Get input
IF Keyword_Set(noprompt) THEN BEGIN
junk = Get_KBRD(1)
ENDIF ELSE BEGIN
Print, 'Hit any key to continue...'
junk = Get_KBRD(1)
Print, 'Continuing...
ENDELSE
; Clear typeahead buffer after input
WHILE Get_KBRD(0) do junk=1
END
Here is a version from Arthur Vigan that allows you to interrup operations with the Escape key.
pro hak, NoPrompt=noprompt
on_error,2
;; Clear typeahead buffer before input
while get_kbrd(0) do junk = 1
;; Get input
if Keyword_set(noprompt) then begin
junk = get_kbrd(1)
endif else begin
print, 'Hit any key to continue...'
junk = get_kbrd(1)
endelse
;; Clear typeahead buffer after input
while get_kbrd(0) do tmp = 1
;; ESCape character
if (byte(junk) eq 27) $
then message,' --> escape key pressed! Stopping...', $
/noname,/noprefix,/reset
end
![]()
Copyright © 2004 David W. Fanning
Written 3 December 2004
Last Updated 6 March 2014