Print Page | Close Window

Cursor position

Printed From: Rocket Software
Category: AccuTerm Knowledge Base (read only)
Forum Name: Green Screen
Forum Description: General terminal emulation questions
URL: https://forum.asent.com/forum_posts.asp?TID=2502
Printed Date: March 26 2026 at 8:51pm
Software Version: Web Wiz Forums 12.03 - http://www.webwizforums.com


Topic: Cursor position
Posted By: mzitcer
Subject: Cursor position
Date Posted: May 09 2015 at 7:19am
Hi all,

Using the following code to determine cursor position on a mouse click:
PRINT CHAR(27):'[6N'
then trying to parse the output for row and column position.

The output variable XY shows on the screen as:
~
1;29;13

but LEN(XY) = 2 (I assume it stops at the ESC character?) and I can't figure out the FIELD configuration to get out the 29 and 13 that show column and row values.

Any help will be appreciated.
Thanks,
Marc Zitcer



Replies:
Posted By: Shrek59
Date Posted: May 09 2015 at 7:16pm
Hi Marc,

It isn't totally clear to me what you are doing ... Normally, mouse clicks are "captured" via an input routine that collects user input on a character by character basis. Of course, this means you have to assess what has been entered after every character entry.

The mouse click pattern you have shown looks like an ASCII pattern, but the code you have used to retrieve this looks like an ANSI code (i.e. VT420 or similar).

Assuming you have a mouse return code, then this is the code that I use to assess what has happened:

SUBROUTINE GET.MOUSE.INFO(MC.DATA, MOUSE.CLICKED, MSX, MSY)
*****************************************************************************
*
* ASCII mouse pattern = STX b CR ccc.rr CR
*       where: b = mouse button (p = left; q = right, r = centre; CAPS = double-click)
*              ccc = click column (zero based)
*              rr = row           (zero based)
*
EQUATE CR  TO CHAR(13)
EQUATE ESC TO CHAR(27)
EQUATE CSI TO CHAR(155)

MOUSE.CLICKED = @FALSE
MSX = ''
MSY = ''
IF (MC.DATA EQ '') THEN RETURN

TT = OCONV(@TERM.TYPE, 'MCU')
IF (TT[1, 2] EQ 'VT') THEN
  GOSUB ansi
END ELSE
  IF (SEQ(MC.DATA) EQ 002) AND (COUNT(MC.DATA, CR) EQ 2) THEN
    BUTTON = MC.DATA[2, 1]
    MOUSE.CLICKED = CONVERT('pqrPQR', 'lrcLRC', BUTTON)
    CCC.RR = FIELD(MC.DATA, CR, 2)
    MSX = FIELD(CCC.RR, '.', 1) + 0
    MSY = FIELD(CCC.RR, '.', 2) + 0
  END
END

RETURN
*
* ----------------------------------------------------------------------- *
*
ansi:
*
* ANSI mouse pattern = ESC [ n ~ ESC [ r ; c R
*      where: n = mouse button (101 = left, 102 = right, 103 = centre; +10 for double-click)
*             r = row (1 based)
*             c = column (1 based)
*      If AccuTerm is using 8-bit control codes, then ESC [ is sent as CSI.
*
* Note this subroutines converts the row and column numbers to zero based values to be
* consistent with the return values from the ASCII terminals and with MV cursor positioning.
*
BUTTON = ''
BEGIN CASE
  CASE (MC.DATA[1, 1] EQ ESC) AND (MC.DATA[1] EQ 'R') AND (COUNT(MC.DATA, ESC) EQ 2)
    BUTTON = FIELD(FIELD(MC.DATA, '~', 1), '[', 2)
    RC = FIELD(MC.DATA, '[', 3)
    CONVERT 'R' TO '' IN RC
    MSX = FIELD(RC, ';', 2) - 1
    MSY = FIELD(RC, ';', 1) - 1

  CASE (MC.DATA[1] EQ 'R') AND (COUNT(MC.DATA, CSI) EQ 2)
    BUTTON = FIELD(FIELD(MC.DATA, '~', 1), CSI, 2)
    RC = FIELD(MC.DATA, CSI, 3)
    CONVERT 'R' TO '' IN RC
    MSX = FIELD(RC, ';', 2) - 1
    MSY = FIELD(RC, ';', 1) - 1
END CASE

IF (BUTTON NE '') THEN
  LRC = BUTTON[1]
  DBL = BUTTON[2, 1]
  MOUSE.CLICKED = CONVERT('123', 'lrc', LRC)
  IF (DBL) THEN MOUSE.CLICKED = OCONV(MOUSE.CLICKED, 'MCU')
END

RETURN
*
* ----------------------------------------------------------------------- *
*
END

The above is for use with UniVerse or OpenQM. You may need to change the @Variables for use with D3 or some other database.

You pass the mouse string in as MC.DATA, and get back the variables MOUSE.CLICKED (null or the mouse button - upper case if double-click), MSX (screen x position), and MSY (screen Y position).

The ASCII code is what we use. The rest is there for completeness, but probably isn't fully tested.

I hope this helps.

Brian Speirs


Posted By: mzitcer
Date Posted: May 11 2015 at 4:11pm
Hi Shrek,

I am running a VT emulation under Accuterm 7.  The returned string mc.data SHOULD be ANSII, but that conversion doesn't work.  The returned code is:

~
1;xx;yy

LEN(mc.data) = 2
COUNT(mc.data,CR) = 0

Parsing mc.data to hex gives me 02 (stx) 7E (~) then nothing further showing the 1;xx;yy portion of mc.data.  I would think that the next character should be a carriage return or line feed but there is nothing else there!

Any thoughts?

Marc




Posted By: Shrek59
Date Posted: May 12 2015 at 3:32am
Hi Marc,

It looks like you have SystemBuilder mode turned on - i.e. you have issued an ESC STX 2 command somewhere along the way. This reports a mouse position as:

  STX ~ CR b ; c ; r CR

See Mouse function under AccuTerm Programming in the User Manual.

You have captured the bit up to the carriage return. The next bit is displayed on the screen in your original post as: 1;29;13  meaning left button, column 29, row 13.

So - you aren't capturing the mouse click properly (and I'd also question why you have SystemBuilder mode enabled). As I noted earlier, mouse clicks are usually captured by input routines that examine every character sent by keystrokes. You aren't doing that (because your capture was ended by the CR).

Look at subroutine SUI.INPUT.TEXT in the SUIBP file as an example of this type of input routine. In fact, play with the SUI demo programs that come with AccuTerm as they demonstrate the use of mouse and function keys.

HTH,

Brian


Posted By: mzitcer
Date Posted: May 12 2015 at 1:19pm
Hi Brian,

I used the ESC STX 2 command to turn on mouse reporting in Accuterm.  Thanks to your suggestion, I was able to modify SUI.INPUT.CHAR  and parse the output to give me row and column positions.  The thing that had me going was how to exit the LOOP without having to enter another character.  Got around it by using a FOR/NEXT to capture the 5 characters I actually needed.

Thanks for the help!
Marc



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.03 - http://www.webwizforums.com
Copyright ©2001-2019 Web Wiz Ltd. - https://www.webwiz.net