Ejemplo n.º 1
0
 public static void save2Ngraph(Ngraph ngraph)
 {
     if (ngraph.Duration > 0 && ngraph.Graph.Length > 0)
     {
         ngraphs.Add(ngraph);
     }
 }
Ejemplo n.º 2
0
        public static void readNgraphsFromFile(String path)
        {
            Ngraph n;

            fs = new FileStream(path, FileMode.Open);
            sr = new StreamReader(fs, Encoding.UTF8);
            string fs_line = "";
            int    j       = 0;
            int    k       = 0;

            while ((fs_line = sr.ReadLine()) != null)
            {
                j = 0;
                k = 0;
                for (int i = 0; i < fs_line.Length; i++)
                {
                    if (fs_line.ToCharArray()[i] == ';' && j == 0)
                    {
                        j = i;
                    }
                }

                for (int i = j + 1; i < fs_line.Length; i++)
                {
                    if (fs_line.ToCharArray()[i] == ';')
                    {
                        k = i;
                    }
                }

                if (fs_line.Length > 2)
                {
                    try
                    {
                        n = new Ngraph(fs_line.Substring(0, j),
                                       Int32.Parse(fs_line.Substring(j + 1, k - j - 1)),
                                       Int32.Parse(fs_line.Substring(k + 1, fs_line.Length - k - 1)));
                        old_ngraphs.Add(n);
                    }catch (Exception e)
                    {
                        Debug.WriteLine(e.ToString());
                    }
                }
            }
            fs.Close();
            sr.Close();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Calculates the distance A between this and Ngraph n
 /// </summary>
 /// <param name="n">New ngraph to compare with</param>
 /// <returns>The distance A</returns>
 public double calcDistanceA(Ngraph n)
 {
     return(0d);
 }
Ejemplo n.º 4
0
        private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (STATE == PASSIVE)
            {
                return(CallNextHookEx(_hookID, nCode, wParam, lParam));
            }
            long milliseconds = 0;

            Keys key1;

            key1      = (Keys)Marshal.ReadInt32(lParam);
            keyString = key1.ToString();
            //Debug.Write(keyString);

            // account for german keyboard layout:
            if (keyString.Equals("OemOpenBrackets"))
            {
                keyString = "ß";
            }
            else if (keyString.Equals("Oem10"))
            {
                keyString = "Ü";
            }
            else if (keyString.Equals("Oemtilde"))
            {
                keyString = "Ö";
            }
            else if (keyString.Equals("Oem7"))
            {
                keyString = "Ä";
            }
            else if (keyString.Equals("Oem1"))
            {
                keyString = "Ä";
            }
            //else if (keyString.Length > 3 && keyString.Substring(0, 3).Equals("Num")) keyString = keyString.Substring(6, 1); //Numpad
            //else if (keyString.Length == 2 && keyString.Substring(0, 1).Equals("D")) keyString = keyString.Substring(1, 1); //Numbers

            //Debug.WriteLine(" "+keyString);

            if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
            {
                //accuont

                milliseconds = DateTimeOffset.Now.ToUnixTimeMilliseconds();
                //Console.WriteLine("Diff: " + (milliseconds - time_last_key)/1000);
                if ((milliseconds - time_last_key) / 1000 > 3 || //reset after 3 seconds of not typing
                                                                 //key.ToString().Equals("Backspace") ||        //or after pressing Space/Enter
                    keyString.Equals("Space") ||
                    keyString.Equals("Return"))
                //key.ToString().Equals("Esc"))
                {
                    //Console.WriteLine("Reset variables");
                    //                    Console.WriteLine("STATE: " + STATE);
                    if (STATE == ENROLLMENT)
                    {
                        writeOut();
                    }
                    if (STATE == VALIDATION)
                    {
                        compare();
                        ngraphs.Clear();
                    }
                    init_ngraphs();
                }
                else if (keyString.Length == 1) //only take letters/numbers into account
                {
                    //2-graphs
                    keys_2g[cnt_2g] = keyString;
                    //Debug.WriteLine("keys2g: " + keys_2g[cnt_2g]);
                    millis_2g[cnt_2g] = milliseconds;
                    cnt_2g++;

                    if (cnt_2g == 3) //three consecutive keys without keyup
                    {
                        long dur = millis_2g[2] - millis_2g[0];
                        digraph = new Ngraph(keys_2g[0] + keys_2g[1], (int)dur, 1);
                        cnt_2g  = 2;
                        for (int i = 0; i < cnt_2g; i++)
                        {
                            keys_2g[i]   = keys_2g[i + 1];
                            millis_2g[i] = millis_2g[i + 1];
                        }

                        //Debug.Write("2_down: " + digraph.Graph + " ");
                        //Debug.WriteLine(digraph.Duration);
                        save2Ngraph(digraph);
                    }

                    //3-graphs
                    keys_3g[cnt_3g]   = keyString;
                    millis_3g[cnt_3g] = milliseconds;
                    cnt_3g++;

                    if (cnt_3g == 4) //four consecutive keys without keyup
                    {
                        long dur = millis_3g[3] - millis_3g[0];
                        trigraph = new Ngraph(keys_3g[0] + keys_3g[1] + keys_3g[2], (int)dur, 1);
                        cnt_3g   = 3;
                        for (int i = 0; i < cnt_3g; i++)
                        {
                            keys_3g[i]   = keys_3g[i + 1];
                            millis_3g[i] = millis_3g[i + 1];
                        }

                        // Debug.Write("3_down: " + trigraph.Graph + " ");
                        // Debug.WriteLine(trigraph.Duration);
                        save2Ngraph(trigraph);
                    }

                    //4-graphs
                    keys_4g[cnt_4g]   = keyString;
                    millis_4g[cnt_4g] = milliseconds;
                    cnt_4g++;

                    if (cnt_4g == 5) //five consecutive keys without keyup
                    {
                        long dur = millis_4g[4] - millis_4g[0];
                        fourgraph = new Ngraph(keys_4g[0] + keys_4g[1] + keys_4g[2] + keys_4g[3], (int)dur, 1);
                        cnt_4g    = 4;
                        for (int i = 0; i < cnt_4g; i++)
                        {
                            keys_4g[i]   = keys_4g[i + 1];
                            millis_4g[i] = millis_4g[i + 1];
                        }

                        //Debug.Write("4_down: " + fourgraph.Graph + " ");
                        //Debug.WriteLine(fourgraph.Duration);
                        save2Ngraph(fourgraph);
                    }

                    //5-graphs
                    keys_5g[cnt_5g]   = keyString;
                    millis_5g[cnt_5g] = milliseconds;
                    cnt_5g++;

                    if (cnt_5g == 6) //six consecutive keys without keyup
                    {
                        long dur = millis_5g[5] - millis_5g[0];
                        fivegraph = new Ngraph(keys_5g[0] + keys_5g[1] + keys_5g[2] + keys_5g[3] + keys_5g[4], (int)dur, 1);
                        cnt_5g    = 5;
                        for (int i = 0; i < cnt_5g; i++)
                        {
                            keys_5g[i]   = keys_5g[i + 1];
                            millis_5g[i] = millis_5g[i + 1];
                        }

                        //Debug.Write("5_down: " + fivegraph.Graph + " ");
                        //Debug.WriteLine(fivegraph.Duration);
                        save2Ngraph(fivegraph);
                    }

                    //Debug.Write(milliseconds + " ");
                    //Debug.WriteLine(key.ToString());
                }
            }

            if (nCode >= 0 && wParam == (IntPtr)WM_KEYUP)
            {
                milliseconds = DateTimeOffset.Now.ToUnixTimeMilliseconds();

                if (keyString.Length == 1) //only take letters/numbers into account
                                           //key.ToString().StartsWith("NumPad"))  //also check for number in numpad
                {
                    //2-graphs
                    //Debug.WriteLine("cnt 2g: " + cnt_2g);
                    if (cnt_2g >= 2 && keyString.Equals(keys_2g[1]))
                    {
                        long dur = milliseconds - millis_2g[0];
                        digraph = new Ngraph(keys_2g[0] + keys_2g[1], (int)dur, 1);

                        cnt_2g       = 1;
                        keys_2g[0]   = keys_2g[1];
                        millis_2g[0] = millis_2g[1];


                        //Debug.Write("2_up: " + digraph.Graph + " ");
                        //Debug.WriteLine(digraph.Duration);
                        save2Ngraph(digraph);
                    }


                    //3-graphs
                    if (cnt_3g >= 3 && keyString.Equals(keys_3g[2]))
                    {
                        long dur = milliseconds - millis_3g[0];
                        trigraph = new Ngraph(keys_3g[0] + keys_3g[1] + keys_3g[2], (int)dur, 1);

                        cnt_3g = 2;
                        for (int i = 0; i < cnt_3g; i++)
                        {
                            keys_3g[i]   = keys_3g[i + 1];
                            millis_3g[i] = millis_3g[i + 1];
                        }

                        //Debug.Write("3_up: " + trigraph.Graph + " ");
                        //Debug.WriteLine(trigraph.Duration);
                        save2Ngraph(trigraph);
                    }

                    //4-graphs
                    if (cnt_4g >= 4 && keyString.Equals(keys_4g[3]))
                    {
                        long dur = milliseconds - millis_4g[0];
                        fourgraph = new Ngraph(keys_4g[0] + keys_4g[1] + keys_4g[2] + keys_4g[3], (int)dur, 1);

                        cnt_4g = 3;
                        for (int i = 0; i < cnt_4g; i++)
                        {
                            keys_4g[i]   = keys_4g[i + 1];
                            millis_4g[i] = millis_4g[i + 1];
                        }

                        //Debug.Write("4_up: " + fourgraph.Graph + " ");
                        //Debug.WriteLine(fourgraph.Duration);
                        save2Ngraph(fourgraph);
                    }


                    //5-graphs
                    if (cnt_5g >= 5 && keyString.Equals(keys_5g[4]))
                    {
                        long dur = milliseconds - millis_5g[0];
                        fivegraph = new Ngraph(keys_5g[0] + keys_5g[1] + keys_5g[2] + keys_5g[3] + keys_5g[4], (int)dur, 1);

                        cnt_5g = 4;
                        for (int i = 0; i < cnt_5g; i++)
                        {
                            keys_5g[i]   = keys_5g[i + 1];
                            millis_5g[i] = millis_5g[i + 1];
                        }

                        // Debug.Write("5_up: " + fivegraph.Graph + " ");
                        //Debug.WriteLine(fivegraph.Duration);
                        save2Ngraph(fivegraph);
                    }
                }
            }
            if (milliseconds > 0)
            {
                time_last_key = milliseconds;
            }

            return(CallNextHookEx(_hookID, nCode, wParam, lParam));
        }