Example #1
0
 // Rebind function that takes a key as paramter instead of having a new function for every single button
 public void Rebind(InputManager.Keys key)
 {
     // Stops the player from moving
     inputManager.transform.parent.GetComponent <PlayerMovement>().move = false;
     // Starts a coroutine
     StartCoroutine(Test(key));
 }
Example #2
0
    // TODO: change name of function to better represent what it does
    public IEnumerator Test(InputManager.Keys key)
    {
        // Enables a window telling player what to do
        window.SetActive(true);

        // done is used to check when if a player has pressed a new key, default it to false
        done = false;

        // Saves the old key incase player wants to abort keybinding
        KeyCode old = inputManager.RemoveKey(key);

        while (true)
        {
            // If the player has pressed a key
            if (done)
            {
                // Checks if new keybinding has been added successfully
                if (inputManager.AddKey(key, code))
                {
                    break;  // Exits the while loop
                }
                // If not added successfully, we try again for a new key
                done = false;
                code = KeyCode.None;
            }
            // If player aborts keybinding
            else if (stop)
            {
                // Re adds the old key
                inputManager.AddKey(key, old);
                stop = false;
                break;  // Exits the while loop
            }
            // Yield so other code/threads can run
            yield return(null);
        }

        // Enables player to move again and disables info window
        inputManager.transform.parent.GetComponent <PlayerMovement>().move = true;
        window.SetActive(false);
    }
 private static void PressKey(Keys k, int timeInMS = 50)
 {
     Keyboard.KeyDown(k);
     Thread.Sleep(timeInMS);
     Keyboard.KeyUp(k);
 }
        void keyToCode(string musicKey, out Keys code, out int coctave)
        {
            //C3
            musicKey = musicKey.Replace("Sharp", "");
            musicKey = musicKey.TrimEnd('+', '-');
            coctave = int.Parse("" + musicKey[1]);
            int codekey = key.IndexOf(musicKey[0]);

            switch (codekey)
            {
                case 0:
                    code =  Keys.D1;
                    if (coctave == octave + 1 || coctave == 6)
                    {
                        code = Keys.D8;
                        coctave = octave;
                    }
                    break;
                case 1:
                    code =  Keys.D2; break;
                case 2:
                    code =  Keys.D3; break;
                case 3:
                    code =  Keys.D4; break;
                case 4:
                    code =  Keys.D5; break;
                case 5:
                    code =  Keys.D6; break;
                case 6:
                    code =  Keys.D7; break;
                case 7:
                    code =  Keys.D8; break;
                default:
                    code =  0;
                    break;
            }
        }
        public void queueKeyPress(Keys xmidikey,  int deltaOctave)
        {
            midikey k = new midikey();
            k.k = xmidikey;
            k.deltaOctave = deltaOctave;
            lock(locker)
            {
                keyQueue.Enqueue(k);

            }
        }
        // Catch User Key Presses
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if ( btnKeyFrmPress.Enabled == false)
            {
                cbPressValue.SelectedItem = keyData.ToString();

                btnKeyFrmPress.Enabled = true;
                btnKeyFrmPress.Text = "From Press";

                return true; // handled key input.
            }

            // Call the base class
            return base.ProcessCmdKey(ref msg, keyData);
        }