Beispiel #1
0
        public static ButtonState MouseStrokeToButtonState(ManagedWrapper.Stroke stroke)
        {
            int    state = stroke.mouse.state;
            ushort btn   = 0;

            if (state < 0x400)
            {
                while (state > 2)
                {
                    state >>= 2;
                    btn++;
                }
                state = 2 - state; // 1 = Pressed, 0 = Released
            }
            else
            {
                if (state == 0x400)
                {
                    btn = 5;                 // Vertical mouse wheel
                }
                else if (state == 0x800)
                {
                    btn = 6;                      // Horizontal mouse wheel
                }
                state = stroke.mouse.rolling < 0 ? -1 : 1;
            }
            return(new ButtonState {
                Button = btn, State = state
            });
        }
Beispiel #2
0
        /// <summary>
        /// Converts a button index plus a state into a State value for a mouse Stroke
        /// </summary>
        /// <param name="btn">0 = LMB, 1 = RMB etc</param>
        /// <param name="state">1 = Press, 0 = Release</param>
        /// <returns>A State value for a Mouse Stroke</returns>
        public static ManagedWrapper.Stroke MouseButtonAndStateToStroke(int btn, int state)
        {
            var stroke = new ManagedWrapper.Stroke();
            var power  = btn < 5 ? btn * 2 + (state == 0 ? 1 : 0) : btn + 5;

            stroke.mouse.state = (ushort)(1 << power);
            if (btn >= 5)
            {
                stroke.mouse.rolling = (short)(state * 120);
            }
            return(stroke);
        }
Beispiel #3
0
        public static KeyboardState KeyboardStrokeToKeyboardState(ManagedWrapper.Stroke stroke)
        {
            var code   = stroke.key.code;
            var state  = stroke.key.state;
            var retVal = new KeyboardState();

            if (code == 54)
            {
                // Interception seems to report Right Shift as 54 / 0x36 with state 0/1...
                // ... this code is normally unused (Alt-SysRq according to linked page) ...
                // ... and AHK uses 54 + 256 = 310 (0x36 + 0x100 = 0x136)...
                // ... so change the code, but leave the state as 0/1
                code = 310;
            }

            // If state is shifted up by 2 (1 or 2 instead of 0 or 1), then this is an "Extended" key code
            if (state > 1)
            {
                if (code == 42 || state > 3)
                {
                    // code == 42
                    // Shift (42/0x2a) with extended flag = the key after this one is extended.
                    // Example case is Delete (The one above the arrow keys, not on numpad)...
                    // ... this generates a stroke of 0x2a (Shift) with *extended flag set* (Normal shift does not do this)...
                    // ... followed by 0x53 with extended flag set.
                    // We do not want to fire subsriptions for the extended shift, but *do* want to let the key flow through...
                    // ... so that is handled here.
                    // When the extended key (Delete in the above example) subsequently comes through...
                    // ... it will have code 0x53, which we shift to 0x153 (Adding 256 Dec) to signify extended version...
                    // ... as this is how AHK behaves with GetKeySC()

                    // state > 3
                    // Pause sends code 69 normally as state 0/1, but also LCtrl (29) as state 4/5
                    // Ignore the LCtrl in this case

                    // Set flag to indicate ignore
                    retVal.Ignore = true;
                }
                else
                {
                    // Extended flag set
                    // Shift code up by 256 (0x100) to signify extended code
                    code  += 256;
                    state -= 2;
                }
            }

            retVal.Code  = code;
            retVal.State = (ushort)(1 - state);
            return(retVal);
        }
Beispiel #4
0
        public static ButtonState[] MouseStrokeToButtonStates(ManagedWrapper.Stroke stroke)
        {
            int state = stroke.mouse.state;

            // Buttons
            var buttonStates = new List <ButtonState>();

            foreach (var buttonState in StrokeFlagToButtonState)
            {
                if (state < buttonState.Key)
                {
                    break;
                }
                if ((state & buttonState.Key) != buttonState.Key)
                {
                    continue;
                }

                buttonStates.Add(buttonState.Value);
                state -= buttonState.Key;
            }

            // Wheel
            if ((state & 0x400) == 0x400) // Wheel up / down
            {
                buttonStates.Add(
                    new ButtonState
                {
                    Button = 5,
                    State  = (stroke.mouse.rolling < 0 ? -1 : 1),
                    Flag   = 0x400
                }
                    );
            }
            else if ((state & 0x800) == 0x800) // Wheel left / right
            {
                buttonStates.Add(
                    new ButtonState
                {
                    Button = 6,
                    State  = (stroke.mouse.rolling < 0 ? -1 : 1),
                    Flag   = 0x800
                }
                    );
            }
            return(buttonStates.ToArray());
        }
Beispiel #5
0
        /// <summary>
        /// Converts a button index plus a state into a State value for a mouse Stroke
        /// </summary>
        /// <param name="btn">0 = LMB, 1 = RMB etc</param>
        /// <param name="state">1 = Press, 0 = Release</param>
        /// <returns>A State value for a Mouse Stroke</returns>
        public static ManagedWrapper.Stroke ButtonAndStateToStroke(int btn, int state)
        {
            var stroke = new ManagedWrapper.Stroke();
            var bit    = btn * 2;

            if (state == 0)
            {
                bit += 1;
            }
            if (btn == 5)
            {
                // Mouse wheel
                stroke.mouse.rolling = (short)(state * 120);
            }
            stroke.mouse.state = (ushort)(1 << bit);
            return(stroke);
        }
Beispiel #6
0
        public static ButtonState StrokeStateToButtonState(ManagedWrapper.Stroke stroke)
        {
            int    state = stroke.mouse.state;
            ushort btn   = 0;

            while (state > 2)
            {
                state >>= 2;
                btn++;
            }
            if (btn == 5)
            {
                state = stroke.mouse.rolling < 0 ? -1 : 1;
            }
            else
            {
                state = 2 - state;
            }
            return(new ButtonState {
                Button = btn, State = state
            });
        }