TIP: Click on subject to list as thread! ANSI
echo: quik_bas
to: JOHN ZORTMAN
from: KURT KUZBA
date: 1998-03-17 08:02:00
subject: Reading UNDER mouse...

JZ>   I'd like to have just a simple little SUB, that when
JZ>   called, just returns the ASCII code of the character
JZ>   currently under the mouse pointer in an integer variable
JZ>   I could work with. This would only need work in good ol'
JZ>   standard SCREEN 0...
   All you need to know is the screen location. Given that, you
   can use either direct screen memory PEEK()s or the SCREEN()
   function to get the value under the mouse pointer.
   This example will work in QB or QBasic. Since the mouse uses
   reverse order for X and Y from LOCATE and SCREEN(), I made
   the mouse SUBs switch them for programmer convenience.
'_|_|_|   MOUSECHAR.BAS   PUBLIC DOMAIN   Kurt Kuzba   3/17/1998
'_|_|_|   Reads character under mouse in QBasic or Quick Basic.
'_|_|_|   Requires loading Quick Basic with /L switch.
'_|_|_|   No warrantee or Guarantee given or implied.
DECLARE SUB MouseStatus ()
DECLARE SUB SetPointer ()
DECLARE SUB MousePointer (P$)
DECLARE FUNCTION MouseInit% ()
TYPE Mousedata: S AS LONG: I AS INTEGER: X AS INTEGER
   Y AS INTEGER: B AS INTEGER: END TYPE
DIM SHARED M AS Mousedata, Wide AS INTEGER, High AS INTEGER
WIDTH 80, 25: High = 8: Wide = 8: IF MouseInit THEN SYSTEM
COLOR 7, 1: CLS : MousePointer "on": LOCATE 8, 10
PRINT "Press Left Button to read character under mouse pointer."
LOCATE 10, 10: PRINT "Press Right Button to END"
LOCATE 14, 20: PRINT "Your pointer is on"
LOCATE 12, 20: PRINT "Row     Col"
M.X = 14: M.Y = 36: SetPointer
DO: MouseStatus
   IF (M.X = 12) THEN
      IF (M.Y > 23) AND (M.Y < 28) THEN MousePointer "off"
   END IF: LOCATE 12, 24: PRINT M.X;
   IF (M.X = 12) THEN
      IF (M.Y > 23) AND (M.Y < 28) THEN MousePointer "on"
   END IF
   IF (M.X = 12) THEN
      IF (M.Y > 31) AND (M.Y < 36) THEN MousePointer "off"
   END IF: LOCATE 12, 32: PRINT M.Y;
   IF (M.X = 12) THEN
      IF (M.Y > 31) AND (M.Y < 36) THEN MousePointer "on"
   END IF
   IF M.B = 1 THEN
      IF (M.X = 14) THEN IF M.Y = 40 THEN MousePointer "off"
      LOCATE 14, 40: PRINT CHR$(SCREEN(M.X, M.Y))
      IF (M.X = 14) THEN IF M.Y = 40 THEN MousePointer "on"
   END IF: LOOP UNTIL M.B = 2: SYSTEM
FUNCTION MouseInit% : DEF SEG = 0
   M.S = 256& * PEEK(207) + PEEK(206)
   M.I = 256& * PEEK(205) + PEEK(204) + 2
   ' see if a Mouse Driver is loaded
   DEF SEG = M.S: MouseInit = 0
   IF (M.S OR (M.I - 2)) AND PEEK(M.I - 2) = 207 THEN
      SCREEN 0: LOCATE 12, 30: PRINT "Mouse Driver Not Found!"
      LOCATE 14, 28: PRINT " Load the Mouse and re-try"
      MouseInit% = -1
   ELSE
      CALL absolute(0, 0, 0, 0, M.I)
   END IF: DEF SEG : END FUNCTION
SUB MousePointer (P$) : DEF SEG = M.S
   SELECT CASE P$
      CASE "on": CALL absolute(1, 0, 0, 0, M.I)
      CASE "off": CALL absolute(2, 0, 0, 0, M.I)
   END SELECT: DEF SEG : END SUB
SUB MouseStatus
   ' Left Button = 1   Right Button = 2  Both buttons = 3
   DEF SEG = M.S: CALL absolute(3, M.B, M.Y, M.X, M.I)
   M.Y = M.Y \ Wide + 1: M.X = M.X \ High + 1: DEF SEG : END SUB
SUB SetPointer : DEF SEG = M.S
   ' in text mode Mickey reports 640 x 192
   CALL absolute(4, 0, (M.Y - 1) * Wide, (M.X - 1) * High, M.I)
   DEF SEG : END SUB
'_|_|_|   end   MOUSECHAR.BAS
> ] Remain calm and think. I will help you. - Kwai Chang CPUfan.
---
---------------
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.