コード例 #1
0
        public void applyBinding(string gesture, bool down)
        {
            var b = getBinding(gesture);

            if (b != null && b.KeyMouseEvent != null && b.KeyMouseEvent != "")
            {
                var key = b.KeyMouseEvent;
                var mod = "";
                if (b.KeyMouseEvent.Contains("+"))
                {
                    var tokens = key.Split('+');
                    if (tokens.Length > 1)
                    {
                        key = tokens[1];
                        mod = tokens[0];
                    }
                    else if (tokens.Length > 0)
                    {
                        key = tokens[0];
                    }
                }

                // First handle modifiers
                if (mod.Length > 0)
                {
                    MouseKeyboardSimulator.sendKeyEvent("Left" + mod, down);
                }

                // Handle mouse buttons
                if (key == "LMB")
                {
                    if (down || Fubi.getCurrentTime() - m_lastMouseClick > 1)
                    {
                        MouseKeyboardSimulator.sendMouseButton(MouseKeyboardSimulator.MouseButtonType.LEFT, down);
                        if (!down)
                        {
                            m_lastMouseClick = Fubi.getCurrentTime();
                        }
                    }
                }
                else if (key == "RMB")
                {
                    MouseKeyboardSimulator.sendMouseButton(MouseKeyboardSimulator.MouseButtonType.RIGHT, down);
                }
                else if (key == "MMB")
                {
                    MouseKeyboardSimulator.sendMouseButton(MouseKeyboardSimulator.MouseButtonType.MIDDLE, down);
                }
                else if (key == "X1MB" || key == "X2MB")
                {
                    MouseKeyboardSimulator.sendMouseButton(MouseKeyboardSimulator.MouseButtonType.X, down);
                }
                // Handle keys
                else if (key.Length > 0)
                {
                    MouseKeyboardSimulator.sendKeyEvent(key, down);
                }
            }
        }
コード例 #2
0
        public void applyHandPositionToMouse(uint userID, out float x, out float y, bool leftHand = false)
        {
            x = float.NaN;
            y = float.NaN;

            float handX, handY, handZ, confidence;

            var joint    = FubiUtils.SkeletonJoint.RIGHT_HAND;
            var relJoint = FubiUtils.SkeletonJoint.RIGHT_SHOULDER;

            if (leftHand)
            {
                joint    = FubiUtils.SkeletonJoint.LEFT_HAND;
                relJoint = FubiUtils.SkeletonJoint.LEFT_SHOULDER;
            }

            double timeStamp;

            Fubi.getCurrentSkeletonJointPosition(userID, joint, out handX, out handY, out handZ, out confidence, out timeStamp);

            if (confidence > 0.5f)
            {
                float relX, relY, relZ;
                Fubi.getCurrentSkeletonJointPosition(userID, relJoint, out relX, out relY, out relZ, out confidence, out timeStamp);

                if (confidence > 0.5f)
                {
                    // Take relative coordinates
                    var rawX = handX - relX;
                    var rawY = handY - relY;

                    // Convert to screen coordinates
                    var mapX = m_mapX;
                    if (leftHand)
                    {
                        // Mirror x  area for left hand
                        mapX = -m_mapX - m_mapW;
                    }
                    float newX = (rawX - mapX) / m_mapW;
                    float newY = (m_mapY - rawY) / m_mapH;

                    // Filtering
                    // New coordinate is weighted more if it represents a longer distance change
                    // This should reduce the lagging of the cursor on higher distances, but still filter out small jittering
                    var changeX = newX - m_x;
                    var changeY = newY - m_y;

                    if (Math.Abs(changeX) > float.Epsilon || Math.Abs(changeY) > float.Epsilon && Math.Abs(timeStamp - m_timeStamp) > float.Epsilon)
                    {
                        var changeLength = Math.Sqrt(changeX * changeX + changeY * changeY);
                        var filterFactor = (float)Math.Sqrt(changeLength) * m_smoothingFactor;
                        if (filterFactor > 1.0f)
                        {
                            filterFactor = 1.0f;
                        }

                        // Apply the tracking to the current position with the given filter factor
                        m_x         = (1.0f - filterFactor) * m_x + filterFactor * newX;
                        m_y         = (1.0f - filterFactor) * m_y + filterFactor * newY;
                        m_timeStamp = timeStamp;

                        // Send it
                        MouseKeyboardSimulator.sendMousePos(m_x, m_y);
                        x = m_x;
                        y = m_x;
                    }
                }
            }
        }