Exemplo n.º 1
0
        public Tuple <string, int> GetValidKeyResponse(List <string> validKeys)
        {
            // same as above, but only keys from the validKeys list will be accepted
            // program will not proceed until a correct key is pressed so make sure the user knows what to do
            if (validKeys.Count == 0)
            {
                return(null);
            }
            parentPage.Movable = false;
            var watch = System.Diagnostics.Stopwatch.StartNew();

            CurrentKey = "";
            bool stillTesting = true;

            while (stillTesting)
            {
                Wait(100);
                if (CurrentKey.Length == 2 && CurrentKey[0] == 'D')
                {
                    CurrentKey = CurrentKey.Remove(0, 1);
                }
                foreach (string vk in validKeys)
                {
                    if (CurrentKey == vk)
                    {
                        stillTesting = false;
                        break;
                    }
                }
            }
            watch.Stop();
            parentPage.Movable = true;
            return(new Tuple <string, int>(CurrentKey, (int)watch.ElapsedMilliseconds));
        }
        /***************************        KEYBOARD      ***************************/
        public Tuple <string, int> GetKeyResponse()
        {
            // usage: GetKeyResponse().Item1 will return the capital letter corresponding to the next key pressed by the user
            // GetKeyResponse().Item2 will return time before getting the response (in milliseconds)
            // do not use for keys other than A-Z or 0-9 (unless you know their windows codes)
            parentPage.Movable = false;
            var watch = System.Diagnostics.Stopwatch.StartNew();

            CurrentKey = "";
            while (CurrentKey == "")
            {
                Wait(100);
            }
            watch.Stop();
            if (CurrentKey.Length == 2 && CurrentKey[0] == 'D')
            {
                CurrentKey = CurrentKey.Remove(0, 1);                                                 // remove windows code for digits
            }
            parentPage.Movable = true;
            return(new Tuple <string, int>(CurrentKey, (int)watch.ElapsedMilliseconds));
        }