| Re: keypressed pauses program - how to do that? [message #3149 is a reply to message #3067] |
Tue, 08 November 1994 07:01   |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
frank@chaos.uni-frankfurt.dbp.de (Frank Hoffsuemmer) writes:
> Hi all,
> basically what I have is a program like this:
> FOR loop=0,1000 DO BEGIN
> TVSCL, image(loop)
> WAIT, 2
> ENDFOR
> because the images aren't very big it's quite fast.
> to make it slower I inserted a 'WAIT, 2' after the TVSCL line.
> But that's not what I want to do. It would be much nicer to have something
> like a key-controled slide-show, where e.g. <space> toggles pause/slide mode
> and e.g <return> (in pause mode) advances the images manually.
> I know there's some function for keyboard-stuff in IDL, but I don't know it's
> name, and I have no idea how to implement it, that it works the waz I described
> above. Maybe somebody wrote something similar an can help me out now.
What you want to use is GET_KBRD. This gets a single character from the input
buffer of the keyboard. If you say
Char = GET_KBRD(1)
then the program waits until the user presses one of the keys. If you say
Char = GET_KBRD(0)
then the program reads from the input buffer without waiting, or returns a null
if nothing's there.
One needs to be aware of two things:
1. GET_KBRD only returns a single character. If the key pressed generates an
escape sequence, then repeated calls to GET_KBRD are needed to read in the
entire sequence.
2. The last time I checked, in IDL for Windows, the non-printing characters
such as carriage-return or line-feed, all are read in as the null character.
This isn't true for other platforms.
Here's an example of a program that uses GET_KBRD.
Bill Thompson
============================================================ ===================
PRO PAUSE,SWITCH
;+
; NAME:
; PAUSE
; PURPOSE:
; Pauses until a key is pressed at the keyboard.
; CATEGORY:
; CALLING SEQUENCE:
; PAUSE [, SWITCH ]
; OPTIONAL INPUT PARAMETERS:
; SWITCH - If nonzero and !D.NAME is 'PS', then no action is taken.
; The default value for SWITCH is 0; i.e. PAUSE will take
; effect no matter what plotting device is in use.
; OUTPUTS:
; None.
; OPTIONAL OUTPUT PARAMETERS:
; None.
; COMMON BLOCKS:
; None.
; SIDE EFFECTS:
; If the character entered is "Q", then the PAUSE procedure executes a
; RETALL command.
; RESTRICTIONS:
; The variable SWITCH must not be an array, or of type string.
; PROCEDURE:
; The GET_KBRD function is used.
; MODIFICATION HISTORY:
; William Thompson Applied Research Corporation
; September, 1987 8201 Corporate Drive
; Landover, MD 20785
;-
;
ON_ERROR,2
;
; If SWITCH is passed and is nonzero, then check to see if PAUSE will have any
; effect.
;
IF N_PARAMS(0) EQ 0 THEN SWITCH = 0
IF (SWITCH NE 0) AND (!D.NAME EQ 'PS') THEN RETURN
;
; Force the plot buffer to empty so that the entire current plot is visible.
;
EMPTY
;
; Loop until a character is entered at the keyboard. If the character "Q" is
; pressed, then return to the main level.
;
TEST_CHAR = GET_KBRD(1)
IF STRUPCASE(TEST_CHAR) EQ "Q" THEN RETALL
;
RETURN
END
|
|
|
|