Beispiel #1
0
        /// <summary>
        /// convert the current key into a printable string.  If users want to force upper case or lower case they can change modifiers m (for example, to enable use of the caps lock key, test it outside the function, if its on pass in a kbmodifiers with shift flag, if off pass KBModifiers.None)
        /// </summary>
        /// <param name="k"></param>
        /// <param name="m"></param>
        /// <param name="selectspecials">filters so that specials are included in the string if true</param>
        /// <param name="selectalphas">filters so that alphas are selected if true</param>
        /// <param name="selectnumerics">filters so that numerics are selected if true </param>
        /// <param name="suppressspace">no spaces are output</param>
        /// <returns></returns>
        public static string ToPrintableString(Keys k, KBModifiers m, bool selectspecials, bool selectalphas, bool selectnumerics, bool suppressspace)
        {
            if (IsKeySpace(k) && !suppressspace)
            {
                return(" ");
            }
            else if ((IsKeyAlpha(k) && selectalphas) ||
                     (IsKeyNumber(k) && selectnumerics) ||
                     (treatnumpadasnumeric && IsKeyNumberpad(k) && selectnumerics) ||
                     (selectspecials && ((!IsKeyAlpha(k) && !IsKeyNumeric(k)) || (IsKeyNumber(k) && IsShiftDown(m)))))
            {
                if (IsShiftDown(m))
                {
                    if (!(!selectspecials && IsKeyNumber(k)))
                    {
                        return(shiftedkeysstring[k.GetHashCode()]);
                    }
                }
                else
                {
                    return(unshiftedkeysstring[k.GetHashCode()]);
                }
            }

            return("");

            #region testcode
            //char []ch = new char[1];

            //byte []asciicode = new byte[1];
            //int i = k.GetHashCode();
            //TypeCode tc = k.GetTypeCode();

            //int bused = 0;
            //int chused = 0;
            //bool wascompleted = false;
            //if (i != 0)
            //{
            //    asciicode[0] = Convert.ToByte(k.GetHashCode());

            //    Decoder d = Encoding.ASCII.GetDecoder();

            //    d.Convert(asciicode,0,1,ch,0,1,true,out bused,out chused,out wascompleted);
            //    //d.GetChars(asciicode, 0, 1, ch, 0);

            //    string blah = new string(ch);

            //    return new string(ch);
            //}
            //ch[1] = '\0';

            //if (ch[0] == '\0')
            //    return "";

            // blah.


            //return "";
            #endregion
        }
Beispiel #2
0
 private void CallHandleKBKeyRepeat(Keys repeatkey, KBModifiers m)
 {
     if (HandleKBKeyRepeat != null)
     {
         HandleKBKeyRepeat(repeatkey, m);
     }
 }
Beispiel #3
0
 private void CallHandleKBKeyLost(Keys[] klist, KBModifiers m)
 {
     if (HandleKBKeyLost != null)
     {
         HandleKBKeyLost(klist, m);
     }
 }
Beispiel #4
0
        //private functions - the states call these when a keyboard event happens.  This in turn calls the event, the event then calls all the delegates that have been added to it


        private void CallHandleKBKeyDown(Keys[] klist, Keys focus, KBModifiers m)
        {
            if (HandleKBKeyDown != null)
            {
                HandleKBKeyDown(klist, focus, m);
            }
        }
Beispiel #5
0
 public static bool IsAltDown(KBModifiers m)
 {
     if ((KBModifiers.Alt & m) == KBModifiers.Alt)
     {
         return(true);
     }
     return(false);
 }
Beispiel #6
0
 public static bool IsCtrlDown(KBModifiers m)
 {
     if ((KBModifiers.Ctrl & m) == KBModifiers.Ctrl)
     {
         return(true);
     }
     return(false);
 }
Beispiel #7
0
 public static bool IsShiftDown(KBModifiers m)
 {
     if ((KBModifiers.Shift & m) == KBModifiers.Shift)
     {
         return(true);
     }
     return(false);
 }
Beispiel #8
0
        /// <summary>
        /// gets a bit field (kbmodifiers) indicating which "modifier" keys are down (control, shift, alt)
        /// </summary>
        /// <param name="ks">keyboard state to test</param>
        /// <returns>bit field with modifier keys flagged</returns>
        public static KBModifiers GetModifiers(KeyboardState ks)
        {
            KBModifiers mod = KBModifiers.None;

            Keys[] klist = ks.GetPressedKeys();
            foreach (Keys dwn in klist)
            {
                mod = mod | IsShiftM(dwn);
                mod = mod | IsAltM(dwn);
                mod = mod | IsCtrlM(dwn);
            }

            return(mod);
        }
Beispiel #9
0
 /// <summary>
 /// convert the current key into a printable string given filtering options. Defaults to spaces allowed
 /// </summary>
 /// <param name="k"></param>
 /// <param name="m"></param>
 /// <param name="selectspecials">filters so that specials are included in the string if true</param>
 /// <param name="selectalphas">filters so that alphas are selected if true</param>
 /// <param name="selectnumerics">filters so that numerics are selected if true </param>
 /// <returns></returns>
 public static string ToPrintableString(Keys k, KBModifiers m, bool selectspecials, bool selectalphas, bool selectnumerics)
 {
     return(ToPrintableString(k, m, selectspecials, selectalphas, selectnumerics, false));
 }
Beispiel #10
0
 /// <summary>
 /// convert the current key into a printable string.  Defaults to alphanumerics on and and accounts for shift key
 /// </summary>
 /// <param name="k"></param>
 /// <param name="m"></param>
 /// <param name="selectspecials"></param>
 /// <returns></returns>
 public static string ToPrintableString(Keys k, KBModifiers m, bool selectspecials)
 {
     return(ToPrintableString(k, m, selectspecials, true, true, false));
 }
Beispiel #11
0
 /// <summary>
 /// convert the current key into a printable string.  Defaults to any kind of printable character and accounts for shift key.
 /// </summary>
 /// <param name="k"></param>
 /// <param name="m"></param>
 /// <returns></returns>
 public static string ToPrintableString(Keys k, KBModifiers m)
 {
     return(ToPrintableString(k, m, true, true, true, false));
 }