void initBasedCoords()
 {
     leftButton = new Data("presentationRight.txt");
     rightButton = new Data("presentationLeft.txt");
     open = new Data("openFile.txt");
     close = new Data("closeFile.txt");
 }
Ejemplo n.º 2
0
 public void setPath(String pathName)
 {
     this.path = new Data(pathName);
 }
 // this will analyze and compare the given data/path to the based path.
 public double analyzeData(int gestureNumber,Data nDataL, Data nDataR)
 {
     //this will determine if the gesture is the same (parallel) to the defined gesture
     double nearness = 0;
        // if (graph.Visible)
      //   graph.Close();
     switch (gestureNumber)
     {
         case 1:
             if(!nDataL.Exception())
                 curve = new ParallelCurve(leftButton.getCoords(), nDataL.getCoords(), leftButton.bEquation, leftButton.eqList, nDataL.getCoords2());
             if ((nearness = curve.getNearness()) < 0.15)
             {
                 InputSimulator.SimulateKeyPress(VirtualKeyCode.RIGHT);
                 graph.setDataPoint(leftButton.getCoords(),curve.getExpectedValues(),nDataL.getCoords());
                 graph.Location = new System.Drawing.Point(0, graph.Height);
                 graph.Show();
             }
             break;
         case 2:
             if (!nDataR.Exception())
                 curve = new ParallelCurve(rightButton.getCoords(), nDataR.getCoords(), rightButton.bEquation, rightButton.eqList, nDataR.getCoords2());
             if ((nearness = curve.getNearness()) < 0.15)
             {
                 InputSimulator.SimulateKeyPress(VirtualKeyCode.LEFT);
                 graph.setDataPoint(rightButton.getCoords(), curve.getExpectedValues(), nDataR.getCoords());
                 graph.Location = new System.Drawing.Point(0, graph.Height);
                 graph.Show();
             }
             break;
         case 3:
             if (!nDataL.Exception())
                 curve = new ParallelCurve(open.getCoords(),nDataL.getCoords(),open.bEquation,open.eqList,nDataL.getCoords2());
             if ((nearness = curve.getNearness()) < 0.15)
             {
                 InputSimulator.SimulateKeyPress(VirtualKeyCode.RETURN);
                 graph.setDataPoint(open.getCoords(), curve.getExpectedValues(), nDataL.getCoords());
                 graph.Location = new System.Drawing.Point(0, graph.Height);
                 graph.Show();
             }
             break;
         case 4:
             if (!nDataR.Exception())
                 curve = new ParallelCurve(close.getCoords(),nDataR.getCoords(),close.bEquation,close.eqList,nDataR.getCoords2());
             if ((nearness = curve.getNearness()) < 0.15)
             {
                 InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.MENU, VirtualKeyCode.F4);
                 graph.setDataPoint(close.getCoords(), curve.getExpectedValues(), nDataR.getCoords());
                 graph.Location = new System.Drawing.Point(0, graph.Height);
                 graph.Show();
             }
             break;
         case 7:
             InputSimulator.SimulateKeyPress(VirtualKeyCode.TAB);
             break;
         case 8:
             InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.SHIFT, VirtualKeyCode.TAB);
             break;
     }
     return nearness;
 }
        private void KinectDevice_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            using(SkeletonFrame frame = e.OpenSkeletonFrame())
            {
                if (frame != null)
                {
                    Skeleton skeleton;
                    JointType[] joints;
                    double diff;
                    double diff2;
                    int flagCanvas = 0;
                    int oldPnumber = 0;

                    frame.CopySkeletonDataTo(this._FrameSkeletons);

                    for (int i = 0; i < this._FrameSkeletons.Length; i++)
                   {
                        skeleton = this._FrameSkeletons[i];
                        if (skeleton.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            textBlock5.Text = skeleton.Joints[JointType.HandRight].Position.X.ToString();

                            diff2 = skeleton.Joints[JointType.ShoulderLeft].Position.Z - skeleton.Joints[JointType.WristLeft].Position.Z;
                            diff = skeleton.Joints[JointType.HandLeft].Position.X - skeleton.Joints[JointType.Spine].Position.X;
                            posture.setSkeleton(skeleton);
                            //pNumber = posture.watPost(skeleton, mode);
                            //textBox2.Text = posture.pNumber.ToString() + "|" + mode.ToString();
                            //textBox5.Text = diff2.ToString();
                            string pathName = processName.GetActiveProcessFilePath();
                            string pName = processName.getProcessName(pathName);
                            //textBox4.Text = pName;
                            pNumber = posture.getInitPosture(skeleton);
                            mode = processName.getMode(pName);

                            if (Record) // init posture is met it will start recording the coordinates of the joints
                            {
                                using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\SourceCode\newLeft.txt", true))
                                {
                                    file.WriteLine(skeleton.Joints[JointType.HandLeft].Position.X.ToString() + " " + skeleton.Joints[JointType.HandLeft].Position.Y.ToString());
                                }
                                using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\SourceCode\newRight.txt", true))
                                {
                                    file.WriteLine(skeleton.Joints[JointType.HandRight].Position.X.ToString() + " " + skeleton.Joints[JointType.HandRight].Position.Y.ToString());
                                }

                                textBlock2.Text = gesture.initPosture.ToString();
                                if (mouseMode) //mouse pointer will move depending on the position of the right hand of the user
                                {
                                    textBlock6.Text = mouse.animateMouse(skeleton).ToString();
                                    if (gesture.getTermPosture(skeleton, gesture.initPosture) == 6)
                                    {
                                        mouseMode = false;
                                        Record = false;
                                        File.Delete(@"C:\SourceCode\newLeft.txt");
                                        File.Delete(@"C:\SourceCode\newRight.txt");
                                    }
                                }
                                else if(keyboardOn) // virtual keyboard is on
                                {
                                    keyboard.keyPressed(skeleton);
                                    form3.changeText(keyboard.leftKeyLayer, keyboard.rightKeyLayer);
                                    form3.activateButton(keyboard.lCellNumber, keyboard.rCellNumber,keyboard.lKeypressed,keyboard.rKeypressed);
                                    if (gesture.getTermPosture(skeleton, gesture.initPosture) == 5)
                                    {
                                        keyboardOn = false;
                                        Record = false;
                                        if (form3.Visible)
                                            form3.Close();
                                        File.Delete(@"C:\SourceCode\newLeft.txt");
                                        File.Delete(@"C:\SourceCode\newRight.txt");
                                    }
                                }
                                else if (altTab) // alt + tab
                                {
                                    if (gesture.getTermPosture(skeleton, gesture.initPosture) == 7)
                                    {
                                        InputSimulator.SimulateKeyPress(VirtualKeyCode.TAB);
                                        Thread.Sleep(1000);
                                    }
                                    else if (gesture.getTermPosture(skeleton, gesture.initPosture) == 8)
                                    {
                                        InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.SHIFT, VirtualKeyCode.TAB);
                                        Thread.Sleep(1000);
                                    }
                                    else if (gesture.getTermPosture(skeleton, gesture.initPosture) == -1)
                                    {
                                        altTab = false;
                                        Record = false;
                                        InputSimulator.SimulateKeyUp(VirtualKeyCode.MENU);
                                    }
                                    File.Delete(@"C:\SourceCode\newLeft.txt");
                                    File.Delete(@"C:\SourceCode\newRight.txt");
                                }
                                else
                                {
                                    if (gesture.getTermPosture(skeleton, gesture.initPosture) != 0) // recording of coordinates will stop
                                    {// it means that the terminating posture was met
                                        Record = false;
                                        textBlock3.Text = gesture.termPosture.ToString();
                                        textBlock1.Text = "Record False";
                                        data = new Data("newLeft.txt");
                                        data2 = new Data("newRight.txt");
                                        textBlock4.Text = dataComputation.analyzeData(gesture.termPosture, data, data2).ToString();
                                        File.Delete(@"C:\SourceCode\newLeft.txt");
                                        File.Delete(@"C:\SourceCode\newRight.txt");
                                    }
                                    else
                                    {
                                        InputSimulator.SimulateKeyUp(VirtualKeyCode.MENU);
                                    }
                                }
                            }
                            else
                            {
                                //if (File.Exists(@"D:\acads\CMSC190-2\SP\textfiles\SPbasecoords\openFile.txt"))
                                  //  File.Delete(@"D:\acads\CMSC190-2\SP\textfiles\SPbasecoords\openFile.txt");
                                gesture = new Gesture();
                                if (gesture.getInitPosture(skeleton) != 0)
                                {
                                    if (gesture.getInitPosture(skeleton) == 6)
                                        mouseMode = true;
                                    else if (gesture.getInitPosture(skeleton) == 5)
                                    {
                                        form3.Location = new System.Drawing.Point((int)((SystemParameters.VirtualScreenWidth / 2) - (form3.Width / 2)),
                                                                                            (int)(SystemParameters.VirtualScreenHeight - form3.Height)-42);
                                        if(!form3.Visible)
                                            form3.ShowDialog();
                                        keyboardOn = true;
                                    }
                                    else if (gesture.getInitPosture(skeleton) == 7)
                                    {
                                        InputSimulator.SimulateKeyDown(VirtualKeyCode.MENU);
                                        InputSimulator.SimulateKeyPress(VirtualKeyCode.TAB);
                                        altTab = true;
                                    }
                                    Record = true;
                                    textBlock1.Text = "Record True";
                                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\SourceCode\newLeft.txt", true))
                                    {
                                        file.WriteLine(skeleton.Joints[JointType.HandLeft].Position.X.ToString() + " " + skeleton.Joints[JointType.HandLeft].Position.Y.ToString());
                                    }
                                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\SourceCode\newRight.txt", true))
                                    {
                                        file.WriteLine(skeleton.Joints[JointType.HandRight].Position.X.ToString() + " " + skeleton.Joints[JointType.HandRight].Position.Y.ToString());
                                    }
                                }
                            }

                        }
                   }//end for loop
                }
            }
        }