Ejemplo n.º 1
0
 static KeyDetector()
 {
     foreach (string name in names)
     {
         keyDetectors[name] = new KeyDetector(name);
     }
 }
Ejemplo n.º 2
0
 void DetectedNewKey(KeyCode key)
 {
     UpdateKeyBind(key);
     KeyDetector.KeyReceived -= UpdateKeyBind;
     KeyDetector.InputCheckSetActive(false);
     binding = false;
 }
Ejemplo n.º 3
0
 public void BindNewKey()
 {
     textComp.text = $"Press a key to bind it";
     KeyDetector.InputCheckSetActive(true);
     KeyDetector.KeyReceived += DetectedNewKey;
     binding = true;
 }
Ejemplo n.º 4
0
    static InputMapper()
    {
        defaultSwitchProControllerMap = new Dictionary <string, InputDetector>(11)
        {
            [MOVE_LEFT]     = JoystickAxisDetector.ToJoystickAxisDetector("Joystick0Axis0Negative"),
            [MOVE_RIGHT]    = JoystickAxisDetector.ToJoystickAxisDetector("Joystick0Axis0Positive"),
            [ACCELERATE]    = JoystickButtonDetector.ToJoystickButtonDetector("Joystick0Button10"),
            [JUMP]          = JoystickButtonDetector.ToJoystickButtonDetector("Joystick0Button0"),
            [ATTACK]        = JoystickButtonDetector.ToJoystickButtonDetector("Joystick0Button2"),
            [DODGE]         = JoystickButtonDetector.ToJoystickButtonDetector("Joystick0Button1"),
            [INTERACT]      = JoystickButtonDetector.ToJoystickButtonDetector("Joystick0Button3"),
            [RECOVER]       = JoystickButtonDetector.ToJoystickButtonDetector("Joystick0Button7"),
            [SWITCH_PREV]   = JoystickButtonDetector.ToJoystickButtonDetector("Joystick0Button13"),
            [SWITCH_NEXT]   = JoystickButtonDetector.ToJoystickButtonDetector("Joystick0Button14"),
            [SWITCH_UP]     = JoystickButtonDetector.ToJoystickButtonDetector("Joystick0Button11"),
            [SWITCH_DOWN]   = JoystickButtonDetector.ToJoystickButtonDetector("Joystick0Button12"),
            [SWITCH_CAMERA] = JoystickButtonDetector.ToJoystickButtonDetector("Joystick0Button9"),
            [PAUSE]         = JoystickButtonDetector.ToJoystickButtonDetector("Joystick0Button8")
        };

        defaultKeyboardMap = new Dictionary <string, InputDetector>(11)
        {
            [MOVE_LEFT]     = KeyDetector.ToKeyDetector("A"),
            [MOVE_RIGHT]    = KeyDetector.ToKeyDetector("D"),
            [ACCELERATE]    = KeyDetector.ToKeyDetector("N"),
            [JUMP]          = KeyDetector.ToKeyDetector("W"),
            [ATTACK]        = KeyDetector.ToKeyDetector("J"),
            [DODGE]         = KeyDetector.ToKeyDetector("K"),
            [INTERACT]      = KeyDetector.ToKeyDetector("U"),
            [RECOVER]       = KeyDetector.ToKeyDetector("F"),
            [SWITCH_PREV]   = KeyDetector.ToKeyDetector("Q"),
            [SWITCH_NEXT]   = KeyDetector.ToKeyDetector("E"),
            [SWITCH_UP]     = KeyDetector.ToKeyDetector("Y"),
            [SWITCH_DOWN]   = KeyDetector.ToKeyDetector("H"),
            [SWITCH_CAMERA] = KeyDetector.ToKeyDetector("Tab"),
            [PAUSE]         = KeyDetector.ToKeyDetector("Escape")
        };
    }
Ejemplo n.º 5
0
 // Start is called before the first frame update
 void Start()
 {
     textComp.text = "Press a key";
     KeyDetector.InputCheckSetActive(true);
 }
Ejemplo n.º 6
0
 // Start is called before the first frame update
 void Start()
 {
     textComp.text = "Press a key";
     KeyDetector.InputCheckSetActive(true);
     KeyDetector.KeyReceived += KeyBinderKeyReceived;
 }
Ejemplo n.º 7
0
        private static int Main(string[] args)
        {
            var result = Parser.Default.ParseArguments <Options>(args);

            if (result.Errors.Any()) // prints usage
            {
                Console.WriteLine("Return codes:");
                Console.WriteLine("  Help         : -2");
                Console.WriteLine("  Error        : -1");
                foreach (var k in Enum.GetValues(typeof(Key)).Cast <Key>())
                {
                    Console.WriteLine($"  {k,-12} : {(int) k}");
                }

                Console.WriteLine();
                Console.WriteLine("Credits :");
                Console.WriteLine("  https://github.com/ibsh/libKeyFinder");
                Console.WriteLine("  https://github.com/aybe/libKeyFinder.NET");
                Console.WriteLine("  https://github.com/erikd/libsndfile");

                return(-2);
            }

            var options = result.Value;

            var path = options.Path;

            if (!File.Exists(path))
            {
                Console.WriteLine("File not found");
                return(-1);
            }

            var sf = SndFile.OpenRead(path);

            if (sf == null)
            {
                Console.WriteLine($"File couldn't be opened: '{SndFile.GetErrorMessage()}'.");
                return(-1);
            }

            var format       = sf.Format;
            var frames       = Math.Min(Options.DefaultBlockSize, options.BlockSize);
            var samples      = frames * format.Channels;
            var buffer       = new double[samples];
            var totalFrames  = 0L;
            var totalPercent = 0;
            var kd           = new KeyDetector(format.SampleRate, format.Channels, samples);

            while (true)
            {
                var readFrames = sf.ReadFrames(buffer, frames);
                if (readFrames <= 0)
                {
                    break;
                }

                var readSamples = readFrames * format.Channels;
                for (var i = 0; i < readSamples; i++)
                {
                    kd.SetSample((uint)i, buffer[i]);
                }
                for (var i = readSamples; i < samples; i++)
                {
                    kd.SetSample((uint)i, 0.0d);
                }

                kd.ProgressiveChromagram();
                totalFrames += readFrames;

                var percent = (int)((double)totalFrames / sf.Frames * 100.0d);
                if (percent <= totalPercent)
                {
                    continue;
                }
                var key1 = kd.KeyOfChromagram();
                Console.WriteLine($"{percent,6}% : {key1,-12} ({(int) key1})");
                totalPercent = percent;
            }

            kd.FinalChromagram();
            var key2 = kd.KeyOfChromagram();

            kd.Dispose();
            sf.Dispose();
            Console.WriteLine();
            Console.WriteLine($"Finale  : {key2,-12} ({(int) key2})");
            return((int)key2);
        }
Ejemplo n.º 8
0
 public void BindNewKey()
 {
     textComp.text = $"Press a key to bind it";
     KeyDetector.InputCheckOnce(DetectedNewKey);
     binding = true;
 }