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);
        }
Esempio n. 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));
        }
Esempio n. 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);
        }
        public List <InputDeviceEvent> GetEvents()       // Events use keys enumeration
        {
            ks = keyboard.GetCurrentState();
            KeyboardUpdate[] ke = keyboard.GetBufferedData();

            List <InputDeviceEvent> events = new List <InputDeviceEvent>();

            foreach (KeyboardUpdate k in ke)
            {
                Keys ky = SharpKeyConversion.SharpKeyToKeys(k.Key);
                //System.Diagnostics.Debug.WriteLine("** Sharp key " + k.Key + " " + (int)k.Key + k.IsPressed);
                //System.Diagnostics.Debug.WriteLine( "      => " + ky.ToString() + " norm " + ky.VKeyToString() + ":" + (int)ky );
                events.Add(new InputDeviceEvent(this, (int)ky, k.IsPressed));
            }

            return((events.Count > 0) ? events : null);
        }