The MouseDevice class represents any device, physical or virtual, that is 'connected' to the system, and generally has mouse behaviors.
상속: RawInputDevice
예제 #1
0
        public MouseActivityArgs(MouseDevice device, MouseActivityType activityType, MouseButtonActivity buttonActivity, 
            MouseCoordinateSpace space, MouseMovementType mmType, 
            IntPtr windowHandle,
            int x, int y, short delta, int clicks, int keyflags)
        {
            Device = device;
            ActivityType = activityType;
            ButtonActivity = buttonActivity;
            CoordinateSpace = space;
            MovementType = mmType;
            WindowHandle = windowHandle;

            Clicks = clicks;
            X = x;
            Y = y;
            Delta = delta;
            KeyFlags = keyflags;
        }
예제 #2
0
        // Create a reasonable MouseActivityArgs object that
        // can be dealt with by the rest of the system.
        // Here we turn the raw data into things like button activity
        // as well as mapping the generic information into something
        // applications can deal with.
        public static MouseActivityArgs CreateFromRawInput(MouseDevice device, RAWMOUSE rawMouse)
        {
            int clicks = 0;
            short delta = 0;
            int x = rawMouse.lLastX;
            int y = rawMouse.lLastY;
            IntPtr windowHandle = IntPtr.Zero;
            int keyMasks = 0;

            MouseButtonActivity mbActivity = (MouseButtonActivity)rawMouse.Union1.Struct1.usButtonFlags;
            MouseActivityType maType = ConvertButtonActivityToMouseActivity(mbActivity);
            MouseMovementType mmType = MouseMovementType.Relative;

            if (MouseActivityType.MouseDown == maType)
                clicks = 1;

            // Figure out what type of movement is being reported
            if (User32.MOUSE_MOVE_RELATIVE == (rawMouse.usFlags & User32.MOUSE_MOVE_RELATIVE))
                mmType = MouseMovementType.Relative;
            
            if (User32.MOUSE_MOVE_ABSOLUTE == (rawMouse.usFlags & User32.MOUSE_MOVE_ABSOLUTE))
                mmType = MouseMovementType.Absolute;

            // If there's mouse wheel activity, get the number of detents that are being reported
            if (MouseButtonActivity.MouseWheel == mbActivity)
            {
                delta = (short)rawMouse.Union1.Struct1.usButtonData;
            }

            // Create a keymask to represent the state of the existing pressed keys
            keyMasks = CreateKeyFlagsFromButtonStates((int)rawMouse.ulRawButtons);

            MouseActivityArgs args = new MouseActivityArgs(device, maType, mbActivity, 
                MouseCoordinateSpace.Desktop, mmType, windowHandle, x, y, delta, clicks, keyMasks);

            return args;
        }