HandleKeyUpEvent() public méthode

public HandleKeyUpEvent ( SFKey code, SFKeyModifiers mod, int keyboardIndex ) : bool
code SFKey
mod SFKeyModifiers
keyboardIndex int
Résultat bool
Exemple #1
0
 /// <summary>
 /// This is a workaround for Unity where some modifier keys do not generate a KeyDown/KeyUp event.
 /// NOTE: This does not distinguish between Left and Right modifier keys.
 /// </summary>  
 private void HandleKeyModifier(Event ev, ref bool keyIsDown, EventModifiers modifier, KeyCode keyCode)
 {
     if ((ev.modifiers & modifier) == modifier)
     {
         ev.keyCode = keyCode;
         keyIsDown = true;
         SFMgr.HandleKeyDownEvent(ev);
     }
     else if (keyIsDown)
     {
         ev.keyCode = keyCode;
         SFMgr.HandleKeyUpEvent(ev);
         keyIsDown = false;
     }
 }    
Exemple #2
0
        /// <summary>
        /// Process GamePad keys, axes, and buttons for dispatch to SFManager.
        /// </summary>
        public void Update()
        {
            for (int a = 0; a < GamePads.Length; a++)
            {
                // Let's process GamePad keys first.
                int UnityButtonToSFKey_size = GamePads[a].Keymap.Length;
                for (int i = 0; i < UnityButtonToSFKey_size; i++)
                {
                    if (InputManager.GetButtonDown(GamePads[a].Keymap[i].UnityButton))
                    {
                        SFMgr.HandleKeyDownEvent(GamePads[a].Keymap[i].SFKeyCode, 0, GamePads[a].ControllerIndex);
                    }
                    if (InputManager.GetButtonUp(GamePads[a].Keymap[i].UnityButton))
                    {
                        SFMgr.HandleKeyUpEvent(GamePads[a].Keymap[i].SFKeyCode, 0, GamePads[a].ControllerIndex);
                    }
                }

                // Let's process axis now.
                for (int b = 0; b < GamePads[a].Joysticks.Length; b++)
                {
                    double horizontal = InputManager.GetAxis(GamePads[a].Joysticks[b].HorizontalAxisName);
                    double vertical   = InputManager.GetAxis(GamePads[a].Joysticks[b].VerticalAxisName);

                    bool currR = horizontal > GamePads[a].Joysticks[b].HorizontalAxisThresholdD;
                    bool currL = horizontal < -GamePads[a].Joysticks[b].HorizontalAxisThresholdD;
                    bool currD = vertical < -GamePads[a].Joysticks[b].VerticalAxisThresholdD;
                    bool currU = vertical > GamePads[a].Joysticks[b].VerticalAxisThresholdD;

                    if (currR)
                    {
                        GamePads[a].Joysticks[b].RightTimerF += UnityEngine.Time.deltaTime;

                        if (!GamePads[a].Joysticks[b].RightKeyPressed || GamePads[a].Joysticks[b].RightTimerF > RepeatTimerThresholdF)
                        {
                            GamePads[a].Joysticks[b].RightTimerF = 0f;
                            SFMgr.HandleKeyDownEvent(SFKey.Code.Right, 0, GamePads[a].ControllerIndex);
                            GamePads[a].Joysticks[b].RightKeyPressed = true;
                        }
                    }
                    else
                    {
                        if (GamePads[a].Joysticks[b].RightKeyPressed)
                        {
                            SFMgr.HandleKeyUpEvent(SFKey.Code.Right, 0, GamePads[a].ControllerIndex);
                            GamePads[a].Joysticks[b].RightKeyPressed = false;
                        }
                    }

                    if (currL)
                    {
                        GamePads[a].Joysticks[b].LeftTimerF += UnityEngine.Time.deltaTime;

                        if (!GamePads[a].Joysticks[b].LeftKeyPressed || GamePads[a].Joysticks[b].LeftTimerF > RepeatTimerThresholdF)
                        {
                            GamePads[a].Joysticks[b].LeftTimerF = 0f;
                            SFMgr.HandleKeyDownEvent(SFKey.Code.Left, 0, GamePads[a].ControllerIndex);
                            GamePads[a].Joysticks[b].LeftKeyPressed = true;
                        }
                    }
                    else
                    {
                        if (GamePads[a].Joysticks[b].LeftKeyPressed)
                        {
                            SFMgr.HandleKeyUpEvent(SFKey.Code.Left, 0, GamePads[a].ControllerIndex);
                            GamePads[a].Joysticks[b].LeftKeyPressed = false;
                        }
                    }

                    if (currD)
                    {
                        GamePads[a].Joysticks[b].DownTimerF += UnityEngine.Time.deltaTime;

                        if (!GamePads[a].Joysticks[b].DownKeyPressed || GamePads[a].Joysticks[b].DownTimerF > RepeatTimerThresholdF)
                        {
                            GamePads[a].Joysticks[b].DownTimerF = 0f;
                            SFMgr.HandleKeyDownEvent(SFKey.Code.Down, 0, GamePads[a].ControllerIndex);
                            GamePads[a].Joysticks[b].DownKeyPressed = true;
                        }
                    }
                    else
                    {
                        if (GamePads[a].Joysticks[b].DownKeyPressed)
                        {
                            SFMgr.HandleKeyUpEvent(SFKey.Code.Down, 0, GamePads[a].ControllerIndex);
                            GamePads[a].Joysticks[b].DownKeyPressed = false;
                        }
                    }

                    if (currU)
                    {
                        GamePads[a].Joysticks[b].UpTimerF += UnityEngine.Time.deltaTime;

                        if (!GamePads[a].Joysticks[b].UpKeyPressed || GamePads[a].Joysticks[b].UpTimerF > RepeatTimerThresholdF)
                        {
                            GamePads[a].Joysticks[b].UpTimerF = 0f;
                            SFMgr.HandleKeyDownEvent(SFKey.Code.Up, 0, GamePads[a].ControllerIndex);
                            GamePads[a].Joysticks[b].UpKeyPressed = true;
                        }
                    }
                    else
                    {
                        if (GamePads[a].Joysticks[b].UpKeyPressed)
                        {
                            SFMgr.HandleKeyUpEvent(SFKey.Code.Up, 0, GamePads[a].ControllerIndex);
                            GamePads[a].Joysticks[b].UpKeyPressed = false;
                        }
                    }
                }
            }
        }