public bool IsKeyPressed(System.Windows.Forms.Keys k, bool recheck = false) // check. Optional rescan or use GetEvents. Needs a diff name from above for some reason
        {
            if (recheck || ks == null)
            {
                ks = keyboard.GetCurrentState();
            }

            //var kp = ks.PressedKeys; foreach (var x in kp) System.Diagnostics.Debug.WriteLine($"Keys down SK {x}");

            if (k == Keys.ShiftKey)  // this concept is r or l shift
            {
                return(ks.IsPressed(Key.LeftShift) || ks.IsPressed(Key.RightShift));
            }
            else if (k == Keys.ControlKey)  // this concept is r or l control
            {
                return(ks.IsPressed(Key.LeftControl) || ks.IsPressed(Key.RightControl));
            }
            else if (k == Keys.Menu)  // this concept is r or l alt
            {
                return(ks.IsPressed(Key.LeftAlt) || ks.IsPressed(Key.RightAlt));
            }
            else
            {
                SharpDX.DirectInput.Key ky = SharpKeyConversion.KeysToSharpKey(k);
                return(ks.IsPressed(ky));
            }
        }
        static public bool CheckTranslation(InputDeviceEvent ev) // safe to call without including SharpDirectInput Debug use
        {
            Keys ky   = ToKeys(ev);
            Key  sk   = SharpKeyConversion.KeysToSharpKey(ky);
            Keys back = SharpKeyConversion.SharpKeyToKeys(sk);

            System.Diagnostics.Debug.WriteLine("Check " + ky.VKeyToString() + " -> " + sk + " ->" + back.VKeyToString());
            return(ky == back);
        }
Beispiel #3
0
        public bool IsKeyPressed(Keys k, bool recheck = false) // check. Optional rescan or use GetEvents. Needs a diff name from above for some reason
        {
            if (recheck || ks == null)
            {
                ks = keyboard.GetCurrentState();
            }

            Key ky = SharpKeyConversion.KeysToSharpKey(k);

            return(ks.IsPressed(ky));
        }
Beispiel #4
0
        public bool?IsPressed(string keyname)                            // keyname is in keys
        {
            Key?k = SharpKeyConversion.KeysToSharpKey(keyname.ToVkey()); // to VKEY, then to Sharp key

            if (k != null)
            {
                return((ks != null) ? ks.IsPressed(k.Value) : false);        // use keyboard state to determine
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("FAILED IsPressed " + keyname);
            }

            return(false);
        }