c=======================================================================
c
c dirkeys4.for
c
c The following sample requires a compiler greater that CVF6.1
c To determine if you can use the extended passdirkeys, check
c the passdirkeys entry in DFLIB.F90.  If it has an interface 
c with two entries, one for a logical argument and one for a
c integer argument, then the system should support the extended
c version.
c
c=======================================================================
c
c       Compile/Load Input Line for Standard Graphics Full Screen Window
c
c       f90 /libs:qwins dirkeys4.for
c
c       Compile/Load Input Line for QuickWin Graphics
c
c       f90 /libs:qwin dirkeys2.f90
c
c  Program to illustrate how to get almost every character
c  from the keyboard in QuickWin or Standard Graphics mode.
c  Comment out the deletemenuqq line for Standard Graphics mode.
c
c  If you are doing a standard graphics application,
c  control C will come in as a #03 without further
c  effort.
c
c  In a QuickWin application,  The File menu Exit item must
c  be deleted, and PassDirKeys called with PASS_DIR_CNTRLC
c  get control C.
c
c  Doing passdirkeysqq once is enough. It's a
c  sticky switch, and won't change until you call
c  passdirkeysqq again. 
c
c  passdirkeys controls whether
c  getcharqq gets
c  --------------------
c  directions keys,
c  i.e. arrows, page up,
c  page down, home, end.
c  insert and delete.
c
c  And in QuickWin mode, whether control C
c  is passed.
c 
c  The following values are defined in DFLIB.F90 for use with
c  the integer version of PASSDIRKEYSQQ.
c  PASS_DIR_FALSE   pass nothing special
c  PASS_DIR_TRUE    pass direction keys
c  PASS_DIR_INSDEL  pass above + insert and delete
c  PASS_DIR_CNTRLC  pass above + control c
c
c
c  getcharqq normally gets
c  -----------------------
c  f1-f9 function keys, alphanumerics,
c  punctuation, most control characters
c  but not escape in standard graphics
c  and not control C in QuickWin.
c
c  Control-C comes through in standard
c  graphics mode.
c
c=======================================================================
	use dflib
	
	integer(4) status

	character*1 key1,key2,ch1
c-----below required to keep whole screen appearance 
c-----for standard graphics
      write(*,*) 'Keyboard Initialized' 
c---------------------- done callback initializing------------------------------------
c	don't do this for standard grapics application
c     remove File menu Exit item.
	status = deletemenuqq(1,3) ! stop QuickWin from getting control C

c-------set up to pass all keys to window including control c.        
	status  = passdirkeysqq(PASS_DIR_CNTRLC)
c=======================================================================
c
c     read and print characters
c
c=======================================================================
   10 key1 = getcharqq()

	if(ichar(key1) .eq. 3) then
	  write(*,*) 'Control C Received'
	  write(*,*) "Really want to quit?"
	  write(*,*) "Type Y <cr> to exit, or any other char <cr> to continue."
	  read(*,*) ch1
	  if(ch1.eq."y" .or. ch1.eq."Y") goto 30
	  goto 10
      endif
      
      if(ichar(key1).eq.0) then ! function key?
      key2 = getcharqq()
      write(*,15) ichar(key1),ichar(key2),key2
   15 format(1x,2i12,1x,a1,' function key')
      else
      if(ichar(key1).eq.224) then ! direction key?
      key2 = getcharqq()
      write(*,16) ichar(key1),ichar(key2),key2
   16 format(1x,2i12,1x,a1,' direction key')
      else
      write(*,20) key1,ichar(key1)  ! normal key
   20 format(1x,a1,i11)
      endif
      endif
      go to 10
   30 stop
      end
