コード例 #1
0
        /// <summary>
        /// キーボード入力のイベントを追加します。
        /// </summary>
        /// <param name="inputs">入力イベントのリスト</param>
        /// <param name="flags">キーボードの動作</param>
        /// <param name="key">入力するキー</param>
        public static void AddKeyboardInput(ref List <Input> inputs, KeyboardStroke flags, Keys key)
        {
            int   keyboardFlags = (int)flags | KBD_UNICODE;
            short virtualKey    = (short)key;
            short scanCode      = (short)NativeMethods.MapVirtualKey(virtualKey, 0);

            AddKeyboardInput(ref inputs, keyboardFlags, virtualKey, scanCode, 0, 0);
        }
コード例 #2
0
        public override void Update()
        {
            sc.mouse_newState = newState;
            sc.Update();
            sc.AttackType     = attackType;
            sc.mouse_oldState = oldState;

            foreach (int i in inventory)
            {
                if (attacks.Any(e => e.ID == i))
                {
                    if (attackType == i)
                    {
                        attacks[i - 1].mouse_newState = newState;
                        attacks[i - 1].Update();
                        attacks[i - 1].mouse_newState = oldState;
                    }
                }
            }

            k_newState = Keyboard.GetState();

            if (KeyboardStroke.KeyDown(k_oldState, k_newState, Keys.E))
            {
                if (attackType != inventory.Count)
                {
                    attackType++;
                }
                else
                {
                    attackType = 0;
                }
            }

            if (KeyboardStroke.KeyDown(k_oldState, k_newState, Keys.Q))
            {
                if (attackType != 0)
                {
                    attackType--;
                }
                else
                {
                    attackType = inventory.Count;
                }
            }

            k_oldState = k_newState;

            base.Update();
        }
コード例 #3
0
        public override void Update()
        {
            dd.Update();

            if (toggleDialogue)
            {
                player.enableMovement = false;
                dd.show();

                newState = Keyboard.GetState();

                if (KeyboardStroke.KeyDown(oldState, newState, Keys.Space))
                {
                    prog++;
                }

                oldState = newState;

                switch (level.stageID)
                {
                case 1:
                    switch (prog)
                    {
                    case 0:
                        dd.DrawMessage("???", "who are you?");
                        break;

                    case 1:
                        dd.DrawMessage("you", "a f****t");
                        break;

                    case 2:
                        awaitingDialogue = false;
                        toggleDialogue   = false;
                        break;
                    }
                    break;
                }
            }
            else
            {
                player.enableMovement = true;
                dd.hide();
            }
            base.Update();
        }
コード例 #4
0
        internal void AddKeyboardInput(KeyboardStroke flags, Keys key)
        {
            int   keyboardFlags = (int)flags | 0x0004; //KBD_UNICODE = 0x0004
            short virtualKey    = (short)key;
            short scanCode      = (short)NativeMethods.MapVirtualKey(virtualKey, 0);

            Input input = new Input();

            input.Type                  = 1; // KEYBOARD = 1
            input.U.Keyboard.Flags      = keyboardFlags;
            input.U.Keyboard.VirtualKey = virtualKey;
            input.U.Keyboard.ScanCode   = scanCode;
            input.U.Keyboard.Time       = 0;
            input.U.Keyboard.ExtraInfo  = IntPtr.Zero;

            _inputs.Add(input);
        }
コード例 #5
0
        static void KeyboardInput(KeyboardStroke flags, Keys key)
        {
            int   keyboardFlags = (int)flags | 0x0004; //KBD_UNICODE = 0x0004
            short virtualKey    = (short)key;
            short scanCode      = (short)MapVirtualKey(virtualKey, 0);

            Input input = new Input();

            input.Type                  = 1; // KEYBOARD = 1
            input.U.Keyboard.Flags      = keyboardFlags;
            input.U.Keyboard.VirtualKey = virtualKey;
            input.U.Keyboard.ScanCode   = scanCode;
            input.U.Keyboard.Time       = 0;
            input.U.Keyboard.ExtraInfo  = IntPtr.Zero;

            var inputArray = new[] { input };

            SendInput(inputArray.Length, inputArray, Marshal.SizeOf(typeof(Input)));
            GC.KeepAlive(inputArray);
        }
コード例 #6
0
ファイル: Keyboard.cs プロジェクト: kenberry0728/EasySharp
        public static UserInput CreateKeyboardInput(
            KeyboardStroke flags,
            short virtualKey,
            short scanCode,
            int time,
            int extraInfo)
        {
            var input = new UserInput
            {
                Type = (int)EventType.INPUT_KEYBOARD
            };

            input.Keyboard.Flags      = (int)flags | KBD_UNICODE;
            input.Keyboard.VirtualKey = virtualKey;
            input.Keyboard.ScanCode   = scanCode;
            input.Keyboard.Time       = time;
            input.Keyboard.ExtraInfo  = extraInfo;

            return(input);
        }
コード例 #7
0
        public override void Update()
        {
            newState = Keyboard.GetState();

            if (KeyboardStroke.KeyDown(oldState, newState, Keys.Escape))
            {
                if (paused)
                {
                    paused = false;
                }
                else
                {
                    paused = true;
                }
            }


            oldState = newState;

            if (paused)
            {
                menu.show();
            }
            else
            {
                menu.hide();
            }
            menu.Update();

            if (!game.IsActive)
            {
                paused = true;
            }

            base.Update();
        }
コード例 #8
0
        public override void Update(GameTime gametime)
        {
            newState = Keyboard.GetState();

            if (KeyboardStroke.KeyDown(oldState, newState, Keys.Space))
            {
                keypressed++;
            }

            if (KeyboardStroke.KeyUp(oldState, newState, Keys.Enter))
            {
                keyreleased++;
            }

            oldState = newState;

            keypressedDisp = new Text
            {
                text     = keypressed.ToString(),
                position = new Vector2(300),
                font     = "font",
                color    = Color.Black,
                game     = this.game
            }; keypressedDisp.LoadContent();
            base.Update(gametime);

            keyreleasedDisp = new Text
            {
                text     = keyreleased.ToString(),
                position = new Vector2(600, 300),
                font     = "font",
                color    = Color.Black,
                game     = this.game
            }; keyreleasedDisp.LoadContent();
            base.Update(gametime);
        }
コード例 #9
0
        /// <summary>
        /// キーボード入力のイベントを追加します。
        /// </summary>
        /// <param name="inputs">入力イベントのリスト</param>
        /// <param name="flags">キーボードの動作</param>
        /// <param name="key">入力するキー</param>
        public static void AddKeyboardInput(ref System.Collections.Generic.List <Input> inputs, KeyboardStroke flags, System.Windows.Forms.Keys key)
        {
            int   keyboardFlags = (int)flags | KBD_UNICODE;
            short virtualKey    = (short)key;
            short scanCode      = (short)NativeMethods.MapVirtualKey(virtualKey, 0);

            AddKeyboardInput(ref inputs, keyboardFlags, virtualKey, scanCode, 0, 0);
        }
コード例 #10
0
        public override void Draw(SpriteBatch batch)
        {
            if (visible)
            {
                window.Draw(batch);

                Vector2 titlePosition;
                Vector2 messagePosition;

                titlePosition   = new Vector2(window.rect.X + TitlePadding.X, window.rect.Y + TitlePadding.Y);
                messagePosition = new Vector2(window.rect.X + MessagePadding.X, window.rect.Y + font.MeasureString(title).Y + MessagePadding.Y);

                switch (TitleAlign)
                {
                case Align.Left:
                    titlePosition = new Vector2(window.rect.X + TitlePadding.X, window.rect.Y + TitlePadding.Y);
                    break;

                case Align.Middle:
                    titlePosition = new Vector2(window.rect.X + (window.rect.Width / 2) - (font.MeasureString(title).X / 2) + TitlePadding.X, window.rect.Y + TitlePadding.Y);
                    break;

                case Align.Right:
                    titlePosition = new Vector2(window.rect.X + window.rect.Width - font.MeasureString(title).X - TitlePadding.X, window.rect.Y + TitlePadding.Y);
                    break;
                }

                switch (MessageAlign)
                {
                case Align.Left:
                    messagePosition = new Vector2(window.rect.X + MessagePadding.X, window.rect.Y + font.MeasureString(title).Y + MessagePadding.Y);
                    break;

                case Align.Middle:;
                    messagePosition = new Vector2(window.rect.X + (window.rect.Width / 2) - (font.MeasureString(message).X / 2) + TitlePadding.X, window.rect.Y + font.MeasureString(title).Y + MessagePadding.Y);
                    break;

                case Align.Right:
                    messagePosition = new Vector2(window.rect.X + window.rect.Width - font.MeasureString(message).X - TitlePadding.X, window.rect.Y + font.MeasureString(title).Y + MessagePadding.Y);
                    break;
                }

                //title
                batch.DrawString(font, title, titlePosition, titleColor);

                //message
                batch.DrawString(font, message, messagePosition, messageColor);

                //external forms
                if (Type == type.message)
                {
                    Button cancelButton = selectionButton;

                    cancelButton.rect  = new Rectangle(window.rect.X + (window.rect.Width / 2) - (cancelButton.rect.Width / 2), window.rect.Y + window.rect.Height - cancelButton.rect.Height - buttonYoffset, cancelButton.rect.Width, cancelButton.rect.Height);
                    cancelButton.label = dismissal;
                    cancelButton.Update();
                    cancelButton.Draw(batch);

                    if (cancelButton.pressed)
                    {
                        visible = false;
                        cancelButton.pressed = false;
                    }
                }
                else if (Type == type.yesno)
                {
                    yesButton.Draw(batch);
                    noButton.Draw(batch);
                }
                else
                {
                    //TODO make other dialoguebox types
                    throw new System.Exception("Other dialoguebox types are not yet available. Try them out at a later date");
                }

                newState = Keyboard.GetState();

                //dismissal keys
                foreach (Keys k in DismissKeys)
                {
                    if (KeyboardStroke.KeyDown(oldState, newState, k))
                    {
                        visible = false;
                    }
                }

                oldState = newState;
            }

            base.Draw(batch);
        }
コード例 #11
0
ファイル: Textbox.cs プロジェクト: EpicTofuu/Sh.Framework
        public override void Update()
        {
            k_newState = Keyboard.GetState();

            bool shift;

            if (focus)
            {
                //check for s hift
                if (k_newState.IsKeyDown(Keys.LeftShift) || k_newState.IsKeyDown(Keys.RightShift))
                {
                    shift = true;
                }
                else
                {
                    shift = false;
                }

                //get input
                foreach (Keys k in k_newState.GetPressedKeys())
                {
                    if (!whitelist.Contains(k))
                    {
                        if (KeyboardStroke.KeyDown(k_oldState, k_newState, k))
                        {
                            currentText += utils.ConvertKeyToChar(k, shift);
                        }
                    }
                }

                //get backspace
                if (k_newState.IsKeyDown(Keys.Back) && currentText != "")
                {
                    if (k_oldState.IsKeyUp(Keys.Back))
                    {
                        currentText = currentText.TrimEnd(currentText[currentText.Length - 1]);
                    }

                    if (timer > 40)
                    {
                        currentText = currentText.TrimEnd(currentText[currentText.Length - 1]);
                    }
                    else
                    {
                        timer++;
                    }
                }
                else
                {
                    timer = 0;
                }

                if (k_newState.IsKeyDown(Keys.Tab))
                {
                    focus = false;
                }

                //submit
                if (KeyboardStroke.KeyDown(k_oldState, k_newState, returnKey) && !allowBreak)
                {
                    submit();
                }
            }

            k_oldState = k_newState;

            base.Update();
        }