! DIRKEYS.F90
! This sample demonstrates a utility that will 
! 
!      INTERFACE
!        LOGICAL*4 FUNCTION PASSDIRKEYSQQ(BOOLVAL)
!        LOGICAL*4 BOOLVAL
!        END FUNCTION PASSDIRKEYSQQ
!      END INTERFACE
!
!
!      RES = PASSDIRKEYSQQ(.TRUE.)
!
!      returns the current seeting of PASSDIRKEYS in RES and turns
!      on the flag.  .FALSE. would turn the flag off.  
!
!
!      PASSDIRKEYS effects the behavior of all keyboard input 
!      statements under QuickWin, and only under QuickWin.  It implicitly
!      effects the behavior of the window that is ACTIVE (and usually    
!      in FOCUS) at the time it is called.  IO with the flag on
!      is designed primarily for the GETCHARQQ and INCHARQQ routines.
!      Before doing normal input such as a READ, it is probably
!      desirable to turn the flag off unless one is prepared
!      to interpret direction and page keys occuring during a
!      formatted READ.  When the flag is on, scrolling via the direction
!      and page keys is disabled.  The mouse must be used instead.
!
!      The console GETCHARQQ always returns direction and function keys.
!
!      Function keys are prefixed by a character with a numeric
!      value of zero.  Direction keys are prefixed by a character
!      with a numeric value of 224 (= 16#E0 = 0xE0).
!
!
!               A Short Tutorial on FOCUS and ACTIVE
!
!      When a window acquires FOCUS, either by a mouse click, IO to it, 
!      or by a FOCUSSQQ call, it also becomes the ACTIVE window.  
!      PASSDIRKEYQQ, GETCHARQQ, SETWINDOWCONFIG, and other QuickWin
!      routines which do not take a unit number as an input argument,
!      usually effect the ACTIVE window whether it is in FOCUS or not.
!      If another window is made ACTIVE but is not in FOCUS, these 
!      routines effect the window ACTIVE at the time of the routine
!      call.  This can be somewhat disconcerting since a GETCHARQQ 
!      under these circumstances will expect input from a grayed,
!      background window.  The user would then have to click on that
!      window before input could be typed to it.  The lesson is that
!      under most circumstances, FOCUS and ACTIVE should apply to
!      the same window.  This is the default behavior of QuickWin and
!      a programmer must consciously override this default.
!
!      Therefore, to use these routines which effect the ACTIVE window
!      either do IO to the unit number of the window you wish to put
!      in FOCUS (and also make ACTIVE), or do a FOCUSQQ(unitnum).
!      If only one window is open then that window is the one effected.
!      If several windows are opened, then the last one opened is the
!      one effected since that window will get FOCUS and ACTIVE as a
!      side effect of being opened.  Of course the user can give a
!      window focus by clicking on it.  This is the reason why the
!      message "input pending in . . ." appears at the bottom of
!      an MDI container window.  From this message the user can click
!      on the correct window.
!
!
!
use dflib
implicit none

logical*4 res
character*1 ch, ch1

Print *,"Type X to exit, S to scroll, D to pass Direction keys"

123 continue
ch = getcharqq()
! check for escapes
! 0x00 0x?? is a function key
! 0xE0 0x?? is a direction key
if (ichar(ch) .eq. 0) then
 ch1 = getcharqq()
 print *,"function key follows escape = ",ichar(ch), "  ",ichar(ch1),"  ",ch1
 goto 123
else if (ichar(ch) .eq. 224) then
 ch1 = getcharqq()
 print *,"direction key follows escape = ",ichar(ch),"  ",ichar(ch1),"  ",ch1
 goto 123
else
 print *,ichar(ch),"  ",ch

 if(ch .eq. 'S') then
 res = passdirkeysqq(.false.)
 print *, "Entering Scroll mode ",res
 endif

 if(ch .eq. 'D')  then
 res = passdirkeysqq(.true.)
 print *, "Entering Direction keys mode ",res
 endif

 if(ch .ne. 'X')  go to 123

endif
end



