MOUSE(3)                                                 MOUSE(3)

     NAME
          mouse, cursor - kernel mouse interface

     SYNOPSIS
          bind -a #m /dev

          /dev/mouse
          /dev/mousein
          /dev/mousectl
          /dev/cursor

     DESCRIPTION
          The mouse device provides an interface to the mouse.  There
          is also a cursor associated with the screen; it is always
          displayed at the current mouse position.

          Reading the mouse file returns the mouse status: its posi-
          tion and button state.  The read blocks until the state has
          changed since the last read.  The read returns 49 bytes: the
          letter m followed by four decimal strings, each 11 charac-
          ters wide followed by a blank: x and y, coordinates of the
          mouse position in the screen image; buttons, a bitmask with
          the 1, 2, and 4 bits set when the mouse's left, middle, and
          right buttons, respectively, are down; and msec, a time
          stamp, in units of milliseconds.

          Writing the mouse file, in the same format, causes the mouse
          cursor to move to the position specified by the x and y
          coordinates of the message.  The buttons and msec fields are
          ignored and may be omitted.

          Writes to the mousein file are processed as if they were
          generated by the mouse hardware itself, as extra mouse
          events to be processed and passed back via the mouse file.
          The mousein file, which is exclusive-use, is intended for
          controlling devices, such as USB mice, that are managed by
          user-level software.  Each event should consist of the let-
          ter m followed by delta x, delta y, and buttons as space-
          separated decimal numbers.

          Writing to the mousectl file configures and controls the
          mouse.  The messages are:

          serial n         sets serial port n to be the mouse port.
          ps2              sets the PS2 port to be the mouse port.
          intellimouse     uses the wheel on a Microsoft Intellimouse
                           as the middle button.
          ps2intellimouse  is equivalent to a write of ps2 followed by
                           a write of intellimouse.
          accelerated      turns on mouse acceleration.

     Page 1                       Plan 9            (printed 12/27/24)

     MOUSE(3)                                                 MOUSE(3)

          linear           turns off mouse acceleration
          res n            sets mouse resolution to a setting between
                           0 and 3 inclusive.
          swap             swaps the left and right buttons on the
                           mouse.
          buttonmap xyz    numbers the left, middle, and right mouse
                           buttons x, y, and z, respectively.  If xyz
                           is omitted, the default map, 123, is used.
                           Thus in the default state writing buttonmap
                           321 swaps left and right buttons and writ-
                           ing buttonmap 123 or just buttonmap
                           restores their usual meaning.  Note that
                           buttonmap messages are idempotent, unlike
                           swap.
          reset            clears the mouse to its default state.

          Not all mice interpret all messages; with some devices, some
          of the messages may be no-ops.

          Cursors are described in graphics(2). When read or written
          from or to the cursor file, they are represented in a 72-
          byte binary format.  The first and second four bytes are
          little endian 32-bit numbers specifying the x and y coordi-
          nates of the cursor offset; the next 32 bytes are the clr
          bitmask, and the last 32 bytes the set bitmask.

          Reading from the cursor file returns the current cursor
          information.  Writing to the cursor file sets the current
          cursor information.  A write of fewer than 72 bytes sets the
          cursor to the default, an arrow.

          The mouse and cursor files are multiplexed by rio(1) to give
          the illusion of a private mouse to each of its clients.  The
          semantics are otherwise the same except that notification of
          a window resize is passed to the application using a mouse
          message beginning with r rather than m; see rio(4) for
          details.

          To cope with pointing devices with only two buttons, when
          the shift key is pressed, the right mouse button generates
          middle-button events.

     SOURCE
          /sys/src/9/port/devmouse.c

     SEE ALSO
          rio(4)

     BUGS
          The cursor format is big endian while the rest of the graph-
          ics interface is little endian.

     Page 2                       Plan 9            (printed 12/27/24)

     MOUSE(3)                                                 MOUSE(3)

          The mousein file is disabled.

     Page 3                       Plan 9            (printed 12/27/24)