RAWMOUSE structure (Windows)

Switch View :
ScriptFree
RAWMOUSE structure

Applies to: desktop apps only

Contains information about the state of the mouse.

Syntax

typedef struct tagRAWMOUSE {
  USHORT usFlags;
  union {
    ULONG  ulButtons;
    struct {
      USHORT usButtonFlags;
      USHORT usButtonData;
    };
  };
  ULONG  ulRawButtons;
  LONG   lLastX;
  LONG   lLastY;
  ULONG  ulExtraInformation;
} RAWMOUSE, *PRAWMOUSE, *LPRAWMOUSE;

Members

usFlags

Type: USHORT

The mouse state. This member can be any reasonable combination of the following.

ValueMeaning
MOUSE_ATTRIBUTES_CHANGED
0x04

Mouse attributes changed; application needs to query the mouse attributes.

MOUSE_MOVE_RELATIVE
0

Mouse movement data is relative to the last mouse position.

MOUSE_MOVE_ABSOLUTE
1

Mouse movement data is based on absolute position.

MOUSE_VIRTUAL_DESKTOP
0x02

Mouse coordinates are mapped to the virtual desktop (for a multiple monitor system).

 

ulButtons

Type: ULONG

Reserved.

usButtonFlags

Type: USHORT

The transition state of the mouse buttons. This member can be one or more of the following values.

ValueMeaning
RI_MOUSE_LEFT_BUTTON_DOWN
0x0001

Left button changed to down.

RI_MOUSE_LEFT_BUTTON_UP
0x0002

Left button changed to up.

RI_MOUSE_MIDDLE_BUTTON_DOWN
0x0010

Middle button changed to down.

RI_MOUSE_MIDDLE_BUTTON_UP
0x0020

Middle button changed to up.

RI_MOUSE_RIGHT_BUTTON_DOWN
0x0004

Right button changed to down.

RI_MOUSE_RIGHT_BUTTON_UP
0x0008

Right button changed to up.

RI_MOUSE_BUTTON_1_DOWN
0x0001

RI_MOUSE_LEFT_BUTTON_DOWN

RI_MOUSE_BUTTON_1_UP
0x0002

RI_MOUSE_LEFT_BUTTON_UP

RI_MOUSE_BUTTON_2_DOWN
0x0004

RI_MOUSE_RIGHT_BUTTON_DOWN

RI_MOUSE_BUTTON_2_UP
0x0008

RI_MOUSE_RIGHT_BUTTON_UP

RI_MOUSE_BUTTON_3_DOWN
0x0010

RI_MOUSE_MIDDLE_BUTTON_DOWN

RI_MOUSE_BUTTON_3_UP
0x0020

RI_MOUSE_MIDDLE_BUTTON_UP

RI_MOUSE_BUTTON_4_DOWN
0x0040

XBUTTON1 changed to down.

RI_MOUSE_BUTTON_4_UP
0x0080

XBUTTON1 changed to up.

RI_MOUSE_BUTTON_5_DOWN
0x100

XBUTTON2 changed to down.

RI_MOUSE_BUTTON_5_UP
0x0200

XBUTTON2 changed to up.

RI_MOUSE_WHEEL
0x0400

Raw input comes from a mouse wheel. The wheel delta is stored in usButtonData.

 

usButtonData

Type: USHORT

If usButtonFlags is RI_MOUSE_WHEEL, this member is a signed value that specifies the wheel delta.

ulRawButtons

Type: ULONG

The raw state of the mouse buttons.

lLastX

Type: LONG

The motion in the X direction. This is signed relative motion or absolute motion, depending on the value of usFlags.

lLastY

Type: LONG

The motion in the Y direction. This is signed relative motion or absolute motion, depending on the value of usFlags.

ulExtraInformation

Type: ULONG

The device-specific additional information for the event.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

Winuser.h (include Windows.h)

See also

Reference
GetRawInputDeviceInfo
RAWINPUT
Conceptual
Raw Input

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Content

webJose
Visual Basic 9 Declaration
$0

<StructLayout(LayoutKind.Explicit)> _

Public Structure RAWMOUSE

<FieldOffset(0)> Public usFlags As RAWMOUSEFlags

<FieldOffset(2)> Public ulButtons As UInteger

<FieldOffset(4)> Public usButtonFlags As RAWMOUSEButtonFlags

<FieldOffset(2)> Public usButtonData As UShort

<FieldOffset(6)> Public ulRawButtons As UInteger

<FieldOffset(10)> Public lLastX As Integer

<FieldOffset(14)> Public lLastY As Integer

<FieldOffset(18)> Public ulExtraInformation As UInteger

End Structure

$0 $0Note that fields usButtondata and usButtonFlags are physically swapped. I don't know if it is docummentation bug at this page or some little-endian/big-endian issue, but the structure worksa as I've declared it.$0

2012-02-12:
I beg to differ. A quick C++ test in Windows 7 Ultimate 64-bit revealed the following offsets:

usFlags: 0
ulButtons: 4
usButtonFlags: 4
usButtonData: 6
ulRawButtons: 8
lLastX: 12
lLastY: 16
ulExtraInformation: 20

This is the source code of the test program.

#define _WIN32_WINNT _WIN32_WINNT_WIN7
#define NOMINMAX
#include <Windows.h>
#include <iostream>

#define CAST(x) reinterpret_cast<UINT>(x)
#define SHOW_OFFSET(var, field, b) std::wcout << L#field L": " << CAST(&var.field) - b << std::endl

int main()
{
RAWMOUSE rm;
UINT base = reinterpret_cast<UINT>(&rm);
SHOW_OFFSET(rm, usFlags, base);
SHOW_OFFSET(rm, ulButtons, base);
SHOW_OFFSET(rm, usButtonFlags, base);
SHOW_OFFSET(rm, usButtonData, base);
SHOW_OFFSET(rm, ulRawButtons, base);
SHOW_OFFSET(rm, lLastX, base);
SHOW_OFFSET(rm, lLastY, base);
SHOW_OFFSET(rm, ulExtraInformation, base);
std::wcin.get();
}

I haven't tested my offsets, but I'm confident. I'll ammend this correction if Donny turns out to be right all along.

tywu
RI_MOUSE_HORIZONTAL_WHEEL
I never get RI_MOUSE_HORIZONTAL_WHEEL when I used the horizontal wheel from the RAWMOUSE structure. I do, however, get the WM_HSCROLL message in my message queue although I cannot find a way to retrieve this via the RAWMOUSE structure with GetRawInputData(..).

Blake Coverett
Missing Flag Constant

It isn't defined in the 7.1 SDK version of WinUser.h, but from inspection there should also be a:

#define RI_MOUSE_HORIZONTAL_WHEEL 0x0800

The delta value is stored usButtonData in the same fashion as the vertical wheel. 

The generic HID mouse driver produces these values as of at least Win 7.


Jakub Nietrzeba
Be carefull!
When you are using usButtonData for wheel information notice that this field is unsigned, so this construction:
DWORD dwWheel = usButtonData;
is wrong! This should be:
DWORD dwWheel = (SHORT)usButtonData;