Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29231 ディスカッション

Using C-style Escape Sequence

richpauir
ビギナー
1,095件の閲覧回数
I'm letting the user display characters to a Quickwin child window with return = fputc(unit, character). How can I get the cursor to move back when user hits the BACKSPACE key?

I've tried using an escape sequnce return = fputc(unit, ""C)[] without success.
0 件の賞賛
4 返答(返信)
james1
ビギナー
1,095件の閲覧回数
Haven't used Quickwin but suspect sending a backspace character to a graphics window just adds an escape character symbol to your display, but will not delete the previous character as it would on a console.

You could trap the character (as you are apparently doing now) and rather than sending to the Quickwin window, call the appropriate routines to erase the previous row/column character and place the cursor back in that position, or send a delete key to the window.

James
richpauir
ビギナー
1,095件の閲覧回数
James,
I've thought of testing character = getcharqq() for (ichar(character) == 8) to detect the user pressing the BACKSPACE key before sending the character to the fputc function. However, I'm not sure how to back the cursor up to the previous position. Any suggestions?

Thanks,
Richard
james1
ビギナー
1,095件の閲覧回数
Perhaps something like GETTEXTPOSITION, calculate previous character row/col position, SETTEXTPOSITION, output a space, SETTEXTPOSITION again.

James
llynisa
ビギナー
1,095件の閲覧回数
I have developed a solution along the lines that James suggests, and have used it successfully for several months. I also wanted to halt the program using ESC, so my function for reading in a string and returning with the string and its length (the function value) is:
function ReadVarStr(VarStr)
! Reads in string Varstr entered from the keyboard and returns length of VarStr as value of function. 
use dflib, only: FocusQQ, GetActiveQQ, GetCharQQ, GetTextPosition, OutText,    &
                 rccoord, SetActiveQQ, SetTextPosition
character*(*), intent(inout) :: VarStr
integer*4 acw, i, l, ReadVarStr
character*1 key
TYPE (rccoord) textpos
acw = GetActiveQQ()
i   = SetActiveQQ(0)
i   = 1
do
  call GetTextPosition(textpos)
  key = GetCharQQ()
  l = ICHAR(key)
  if (l == 27) then               ! ESC.
    STOP
  else if (l == 13) then          ! Return.
    call SetTextPosition(textpos.row+1,1,textpos)
    EXIT
  else if (l == 8) then           ! Backspace.
    if (i > 1) then
      i = i-1
      VarStr(i:i) = ' '
      call SetTextPosition(textpos.row,textpos.col-1,textpos)
      call OutText(' ')
      call SetTextPosition(textpos.row,textpos.col-1,textpos)
    end if
  else if (l < 32 .OR. l > 126) then
    CYCLE
  else
    call OutText(key)
    VarStr(i:i) = key
    i = i+1
  end if
end do
ReadVarStr = i-1
acw = FocusQQ(acw)
return
end function ReadVarStr


Alan
返信