Using C-style Escape Sequence

Using C-style Escape Sequence

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.

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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.


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?


Perhaps something like GETTEXTPOSITION, calculate previous character row/col position, SETTEXTPOSITION, output a space, SETTEXTPOSITION again.


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
  call GetTextPosition(textpos)
  key = GetCharQQ()
  l = ICHAR(key)
  if (l == 27) then               ! ESC.
  else if (l == 13) then          ! Return.
    call SetTextPosition(textpos.row+1,1,textpos)
  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
    call OutText(key)
    VarStr(i:i) = key
    i = i+1
  end if
end do
ReadVarStr = i-1
acw = FocusQQ(acw)
end function ReadVarStr


Leave a Comment

Please sign in to add a comment. Not a member? Join today