7

I am using the following code to trap left/right/middle mouse button and mouse row/column in Microsoft QuickBasic 4.5 and I need a way to detect the mouse wheel. I have looked at Ralf Brown's Interrupt List without luck.

The code requires the library QB.QLB.

DECLARE SUB Mouse.Function (Var1!, Var2!)

DIM SHARED MouseX AS INTEGER, MouseY AS INTEGER

TYPE RegTypeX
  AX AS INTEGER
  BX AS INTEGER
  CX AS INTEGER
  DX AS INTEGER
  BP AS INTEGER
  SI AS INTEGER
  DI AS INTEGER
  Flags AS INTEGER
  DS AS INTEGER
  ES AS INTEGER
END TYPE

COMMON SHARED InregsX AS RegTypeX
COMMON SHARED OutregsX AS RegTypeX

DECLARE SUB InterruptX (N AS INTEGER, I AS RegTypeX, O AS RegTypeX)

 CALL Mouse.Function(0, 0) ' init mouse
 CALL Mouse.Function(1, 0) ' show mouse
 DO

 IF LEN(INKEY$) THEN
    CALL Mouse.Function(2, 0) ' hide mouse
    EXIT DO
 END IF

  CALL Mouse.Function(3, 0)

 Var2 = INT((OutregsX.CX - 1) / 8 + 1)
 Var3 = INT((OutregsX.DX - 1) / 8 + 1)

 IF Var3 <> Mouse.Row OR Var2 <> Mouse.Column THEN
    CALL Mouse.Function(2, 0) ' hide mouse
    Mouse.Row = Var3
    Mouse.Column = Var2
    PRINT Mouse.Row, Mouse.Column
    CALL Mouse.Function(1, 0) ' show mouse
 END IF

 Mouse.Button = False
 CALL Mouse.Function(5, 0)
 IF (OutregsX.AX AND 1) = 1 THEN
    IF OutregsX.BX > False THEN
       Mouse.Button = -1
       PRINT "Left-Click"
    END IF
 END IF
 Mouse.Button2 = False
 CALL Mouse.Function(5, 1)
 IF (OutregsX.AX AND 2) = 2 THEN
    IF OutregsX.BX > False THEN
       Mouse.Button2 = -1
       PRINT "Right-Click"
    END IF
 END IF
 Mouse.Button3 = False
 CALL Mouse.Function(5, 2)
 IF (OutregsX.AX AND 4) = 4 THEN
    IF OutregsX.BX > False THEN
       Mouse.Button3 = -1
       PRINT "Middle-Click"
    END IF
 END IF
 LOOP
 END

SUB Mouse.Function (Var1, Var2)
   InregsX.AX = Var1
   InregsX.BX = Var2
   CALL InterruptX(&H33, InregsX, OutregsX)
END SUB

Any ideas?

I recently tried the following code to detect mousewheel in dosbox:

CALL Mouse.Function(5, -1)

Mouse.Wheel = 0
' check mousewheel in BX
Wheel = OutregsX.BX
IF Wheel THEN
   Mouse.Wheel = -1
   PRINT "MouseWheel"
   CALL Mouse.Function(0, 0)
END IF

this does not return anything.

3
  • 5
    Which mouse driver you are using? Not all support the wheel.
    – Justme
    Feb 16, 2021 at 10:15
  • 2
    True, what's the environment (DOS/Windows/emulation) and what driver is used. The mouse wheel is a later add on. Some put it in the button list (Button 2 being press and 3/4 encoding rotation). Start would beto write a little test program monitoring driver function 3 which returns all buttons in BX. Simply read it in a loop while displaying the content of of BX as binary should show any assignment. (Since you don't use the clickcount, this would speed out your detection anyway.)
    – Raffzahn
    Feb 16, 2021 at 10:30
  • Cross-posted on Stack Overflow. Feb 19, 2021 at 11:05

1 Answer 1

12

By the time mice wheels became widely available (starting with the Microsoft IntelliMouse; the Genius EasyScroll was earlier, but we can ignore that here), support for DOS was a secondary concern, and the “standard” DOS drivers and tools never supported them. As a result, there are limited avenues for wheel support in DOS itself, and DOS emulation environments (such as Windows’ NTVDM, or even DOSBox) usually don’t support them.

The only documented API I’m aware of for wheel mice in DOS is that provided by CuteMouse. This works fine with CuteMouse running directly on the hardware, with a PS/2 wheel mouse, or in an environment which will emulate the appropriate PS/2 messages (for example, DOSBox-X with mouse wheel movement remapping disabled, and CuteMouse running).

This adds function 0x11 to interrupt 0x33 to check for wheel support: this will return 0x574D in AX and bit 0 set to 1 in CX is a wheel is supported. Existing functions are changed as follows:

  • functions 0 and 0x21 clear the wheel movement counter;
  • function 3 (get cursor position) returns the accumulated wheel movement in BH, as an 8-bit counter (counting since the last call to function 3, and functions 5 or 6 with BX set to -1);
  • function 5 (get button press) recognises BX value -1 to query the wheel, returning the wheel movement in AH as an 8-bit signed counter, and when querying the wheel specifically, in BX as a 16-bit signed counter, with CX and DX giving the column and row where the wheel was last moved (wheel movement accumulates as for function 3);
  • function 6 (get button release) is altered in the same way as function 5.

Functions 0xC and 0x14 can also be used to register a callback for wheel movement; see the CuteMouse documentation for details.

Mouse wheel clicks are represented as middle-button clicks.

In Quick BASIC, you’d use something like this to detect the wheel:

Mouse.Function(&H11, 0)
IF (OutregsX.AX = &H574D) AND ((OutregsX.CX AND 1) = 1) THEN
  PRINT "Mouse wheel present and supported"
ELSE
  PRINT "Mouse wheel not present and/or not supported"
END IF

If a wheel is present and supported, you’d then use

CALL Mouse.Function(5, -1)
IF OutregsX.BX > 0 THEN
  PRINT "Wheel moved down"
ELSE IF OutregsX.BX < 0 THEN
  PRINT "Wheel moved up"
END IF

At this point, the absolute value of BX gives the amount of wheel movement.

18
  • 2
    Have you looked at mousetst.asm in the CuteMouse source code? You could even start by running mousetst. Are you using CuteMouse? What environment are you testing in? Feb 18, 2021 at 8:37
  • 3
    As far as I’m aware, you won’t be able to get mouse support without CuteMouse, unless you write your own mouse driver. I’ve added a BASIC example showing how to detect wheel support and presence. Feb 19, 2021 at 9:32
  • 1
    I’ve added an example showing how to retrieve the movement too. Feb 19, 2021 at 11:06
  • 1
    Are you using CuteMouse? Feb 22, 2021 at 6:37
  • 1
    And as explained in the answer, the only way you can get this to work if you’re not running directly on the hardware is to use CuteMouse in DOSBox-X (or any other environment which produces wheel PS/2 messages). Feb 22, 2021 at 6:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .