Beispiel #1
0
 /// <summary>
 /// 添加侦听器侦听键。
 /// </summary>
 /// <param name="key">键值。</param>
 /// <param name="callBack">回调函数。</param>
 public void AddKeyListen(KeyCode key, KeyDelegate callBack)
 {
     KeyListener.KeyListenerItem item = new KeyListener.KeyListenerItem();
     item.callBack = callBack;
     item.key      = key;
     items.Add(item);
 }
Beispiel #2
0
    static public void RemoveGlobalListener(KeyDelegate handler)
    {
        globalTable.Remove(handler);

        //KeyBoss.typeCount[typeof(T).ToString()+"+"+typeof(U).ToString()] = globalTable.Count;
        //KeyBoss.Output();
    }
Beispiel #3
0
    // everything
    static public void Invoke(T arg1, U arg2)
    {
        if (arg1 is string)
        {
            //Logger.Log(LogChannel.TRIG, LogLevel.Debug, "Trigger Event <"+arg1.ToString()+"> fired");
        }
        lock (globalTable)
        {
            // backwards to allow for selfdeletion
            for (int i = globalTable.Count - 1; i >= 0; --i)
            {
                KeyDelegate h = globalTable[i];
                h(arg1, arg2);
            }
        }

        lock (selectiveTable)
        {
            KeyDelegate d;
            if (selectiveTable.TryGetValue(arg1, out d))
            {
                d(arg1, arg2);
            }
        }
    }
Beispiel #4
0
            public ListeningWindow(KeyDelegate keyHandlerFunction)
            {
                m_KeyHandler = keyHandlerFunction;

                CreateParams createParams = new CreateParams();

                createParams.Caption   = "Hidden window";
                createParams.ClassName = null;
                createParams.X         = 0x7FFFFFFF;
                createParams.Y         = 0x7FFFFFFF;
                createParams.Height    = 0;
                createParams.Width     = 0;
                createParams.Style     = WS_CLIPCHILDREN;

                this.CreateHandle(createParams);

                unsafe
                {
                    RAWINPUTDEV rawInputDevice = new RAWINPUTDEV();
                    rawInputDevice.usUsagePage = 0x01;
                    rawInputDevice.usUsage     = 0x06;
                    rawInputDevice.dwFlags     = RIDEV_INPUTSINK;
                    rawInputDevice.hwndTarget  = this.Handle.ToPointer();

                    RegisterRawInputDevices(&rawInputDevice, 1, (uint)sizeof(RAWINPUTDEV));
                }
            }
Beispiel #5
0
        public void RegisterListener(KeyCode key, KeyDelegate handler)
        {
            Observer observer;

            if (!observerDict.TryGetValue(key, out observer))
            {
                observer = new Observer(key);
                observerDict.Add(key, observer);
            }
            observer.OnKeyDown += handler;
        }
Beispiel #6
0
        public void RemoveListener(KeyCode key, KeyDelegate handler)
        {
            Observer observer;

            if (observerDict.TryGetValue(key, out observer))
            {
                observer.OnKeyDown -= handler;
                if (observer.Size() == 0)
                {
                    observerDict.Remove(key);
                }
            }
        }
Beispiel #7
0
    static public void AddKeyListener(T key, KeyDelegate handler)
    {
        lock (selectiveTable)
        {
            KeyDelegate d;
            if (selectiveTable.TryGetValue(key, out d))
            {
                selectiveTable[key] = Delegate.Combine(d, handler) as KeyDelegate;
            }
            else
            {
                selectiveTable[key] = handler;
            }

            //KeyBoss.typeCount[typeof(T).ToString()+"+"+typeof(U).ToString()] = selectiveTable.Count;
            //KeyBoss.Output();
        }
    }
Beispiel #8
0
    static public void RemoveKeyListener(T key, KeyDelegate handler)
    {
        lock (selectiveTable)
        {
            KeyDelegate d;
            if (selectiveTable.TryGetValue(key, out d))
            {
                d = Delegate.Remove(d, handler) as KeyDelegate;
                selectiveTable[key] = d;
                if (selectiveTable[key] == null)
                {
                    selectiveTable.Remove(key);
                }
            }

            //KeyBoss.typeCount[typeof(T).ToString()+"+"+typeof(U).ToString()] = selectiveTable.Count;
            //KeyBoss.Output();
        }
    }
Beispiel #9
0
            /// <summary>
            /// Creating an new listening window instance.
            /// </summary>
            /// <param name="keyHandlerFunction"></param>
            public ListeningWindow(KeyDelegate keyHandlerFunction)
            {
                this.m_KeyHandler = keyHandlerFunction;

                CreateParams cp = new CreateParams();

                // Fill in the CreateParams details.
                cp.Caption   = "Hidden window";
                cp.ClassName = null;
                cp.X         = 0x7FFFFFFF;
                cp.Y         = 0x7FFFFFFF;
                cp.Height    = 0;
                cp.Width     = 0;
                ////cp.Parent = parent.Handle;
                cp.Style = WS_CLIPCHILDREN;

                // Create the actual invisible window
                this.CreateHandle(cp);

                // Register for Keyboard notification
                unsafe
                {
                    try
                    {
                        RAWINPUTDEV myRawDevice = new RAWINPUTDEV();
                        myRawDevice.usUsagePage = 0x01;
                        myRawDevice.usUsage     = 0x06;
                        myRawDevice.dwFlags     = RIDEV_INPUTSINK;
                        myRawDevice.hwndTarget  = this.Handle.ToPointer();

                        if (RegisterRawInputDevices(&myRawDevice, 1, (uint)sizeof(RAWINPUTDEV)) == false)
                        {
                            int err = Marshal.GetLastWin32Error();
                            throw new Win32Exception(err, "ListeningWindow::RegisterRawInputDevices");
                        }
                    }
                    catch
                    {
                        throw;
                    }
                }
            }
Beispiel #10
0
            public ListeningWindow(KeyDelegate keyHandlerFunction)
            {
                m_KeyHandler = keyHandlerFunction;

                // Think of a stripped down form control.
                // From System.Windows.Forms namespace.
                CreateParams HiddenControls = new CreateParams();

                // Fill in the CreateParams details.
                HiddenControls.Caption   = "Hidden window";
                HiddenControls.ClassName = null;
                HiddenControls.X         = 0x7FFFFFFF;
                HiddenControls.Y         = 0x7FFFFFFF;
                HiddenControls.Height    = 0;
                HiddenControls.Width     = 0;
                HiddenControls.Parent    = Globule.ParentHandle;
                HiddenControls.Style     = WS_CLIPCHILDREN;

                // Create the actual invisible window
                this.CreateHandle(HiddenControls);

                unsafe
                {
                    RAWINPUTDEV myRawDevice = new RAWINPUTDEV();
                    myRawDevice.usUsagePage = 0x01;
                    myRawDevice.usUsage     = 0x06;
                    myRawDevice.dwFlags     = RIDEV_INPUTSINK;
                    myRawDevice.hwndTarget  = this.Handle.ToPointer();

                    // Register the hidden window as a receiever of
                    // input device messages? See MSDN.
                    if (RegisterRawInputDevices(&myRawDevice, 1,
                                                (uint)sizeof(RAWINPUTDEV)) == false)
                    {
                        int err = Marshal.GetLastWin32Error();
                        throw new Win32Exception(err,
                                                 "ListeningWindow::RegisterRawInputDevices");
                    }
                }
            }
Beispiel #11
0
        /// <summary>Subscribes the detector to all input devices</summary>
        private void subscribeAllEvents()
        {
            // Subscribe to all chat pads
            for (PlayerIndex index = PlayerIndex.One; index <= PlayerIndex.Four; ++index)
            {
                var reporter = new KeyReporter(this.detectedDelegate, (ExtendedPlayerIndex)index);
                var method   = new KeyDelegate(reporter.KeyPressed);
                this.inputService.GetKeyboard(index).KeyPressed += method;
                this.subscribedKeyReporters.Push(method);
            }

            // Subscribe to the main PC keyboard
            {
                var reporter = new KeyReporter(this.detectedDelegate, null);
                var method   = new KeyDelegate(reporter.KeyPressed);
                this.inputService.GetKeyboard().KeyPressed += method;
                this.subscribedKeyReporters.Push(method);
            }

            // Subscribe to the main PC mouse
            {
                var reporter = new MouseButtonReporter(this.detectedDelegate, null);
                var method   = new MouseButtonDelegate(reporter.MouseButtonPressed);
                this.inputService.GetMouse().MouseButtonPressed += method;
                this.subscribedMouseReporters.Push(method);
            }

            // Subscribe to all game pads
            for (
                ExtendedPlayerIndex index = ExtendedPlayerIndex.One;
                index <= ExtendedPlayerIndex.Eight;
                ++index
                )
            {
                var reporter = new GamePadButtonReporter(this.detectedDelegate, index);
                var method   = new GamePadButtonDelegate(reporter.ButtonPressed);
                this.inputService.GetGamePad(index).ButtonPressed += method;
                this.subscribedGamePadReporters.Push(method);
            }
        }
Beispiel #12
0
        public MainMenuState(IGameStateService gameStateService, IGuiService guiService, 
                        IInputService inputService, GraphicsDeviceManager graphics, ContentManager content)
        {
            this.gameStateService = gameStateService;
            this.guiService = guiService;
            this.inputService = inputService;
            this.graphics = graphics;
            this.content = content;

            this.mouseMove = new MouseMoveDelegate(mouseMoved);
            this.keyHit = new KeyDelegate(keyboardEntered);

            mainMenuScreen = new Screen(349, 133);
            /*mainMenuScreen.Desktop.Bounds = new UniRectangle(
              new UniScalar(0.1f, 0.0f), new UniScalar(0.1f, 0.0f), // x and y = 10%
              new UniScalar(0.8f, 0.0f), new UniScalar(0.8f, 0.0f) // width and height = 80%
            );*/

            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);

            LoadContent(mainMenuScreen, content);
        }
            public ListeningWindow(KeyDelegate keyHandlerFunction)
            {
                m_KeyHandler = keyHandlerFunction;

                CreateParams createParams = new CreateParams();

                createParams.Caption = "Hidden window";
                createParams.ClassName = null;
                createParams.X = 0x7FFFFFFF;
                createParams.Y = 0x7FFFFFFF;
                createParams.Height = 0;
                createParams.Width = 0;
                createParams.Style = WS_CLIPCHILDREN;

                this.CreateHandle(createParams);

                unsafe
                {
                    RAWINPUTDEV rawInputDevice = new RAWINPUTDEV();
                    rawInputDevice.usUsagePage = 0x01;
                    rawInputDevice.usUsage = 0x06;
                    rawInputDevice.dwFlags = RIDEV_INPUTSINK;
                    rawInputDevice.hwndTarget = this.Handle.ToPointer();

                    RegisterRawInputDevices(&rawInputDevice, 1, (uint)sizeof(RAWINPUTDEV));
                }
            }
 public void RemoveKeyReleasedEvent(KeyDelegate d)
 {
     mKeyReleasedEvent -= d;
 }
 public void AddKeyReleasedEvent(KeyDelegate d)
 {
     mKeyReleasedEvent += d;
 }
            public ListeningWindow(KeyDelegate keyHandlerFunction)
            {
                m_KeyHandler = keyHandlerFunction;

                CreateParams cp = new CreateParams();

                // Fill in the CreateParams details.
                cp.Caption = "Hidden window";
                cp.ClassName = null;
                cp.X = 0x7FFFFFFF;
                cp.Y = 0x7FFFFFFF;
                cp.Height = 0;
                cp.Width = 0;
                //cp.Parent = parent.Handle;
                cp.Style = WS_CLIPCHILDREN;

                // Create the actual invisible window
                this.CreateHandle(cp);

                // Register for Keyboard notification
                unsafe {
                    try {
                        RAWINPUTDEV myRawDevice = new RAWINPUTDEV();
                        myRawDevice.usUsagePage = 0x01;
                        myRawDevice.usUsage = 0x06;
                        myRawDevice.dwFlags = RIDEV_INPUTSINK;
                        myRawDevice.hwndTarget = this.Handle.ToPointer();

                        if (RegisterRawInputDevices(&myRawDevice, 1, (uint)sizeof(RAWINPUTDEV)) == false) {
                            int err = Marshal.GetLastWin32Error();
                            throw new Win32Exception(err, "ListeningWindow::RegisterRawInputDevices");
                        }
                    }

                    catch { throw; }
                }
            }
    /// <summary>Subscribes the detector to all input devices</summary>
    private void subscribeAllEvents() {

      // Subscribe to all chat pads
      for (PlayerIndex index = PlayerIndex.One; index <= PlayerIndex.Four; ++index) {
        var reporter = new KeyReporter(this.detectedDelegate, (ExtendedPlayerIndex)index);
        var method = new KeyDelegate(reporter.KeyPressed);
        this.inputService.GetKeyboard(index).KeyPressed += method;
        this.subscribedKeyReporters.Push(method);
      }

      // Subscribe to the main PC keyboard
      {
        var reporter = new KeyReporter(this.detectedDelegate, null);
        var method = new KeyDelegate(reporter.KeyPressed);
        this.inputService.GetKeyboard().KeyPressed += method;
        this.subscribedKeyReporters.Push(method);
      }

      // Subscribe to the main PC mouse
      {
        var reporter = new MouseButtonReporter(this.detectedDelegate, null);
        var method = new MouseButtonDelegate(reporter.MouseButtonPressed);
        this.inputService.GetMouse().MouseButtonPressed += method;
        this.subscribedMouseReporters.Push(method);
      }

      // Subscribe to all game pads
      for (
        ExtendedPlayerIndex index = ExtendedPlayerIndex.One;
        index <= ExtendedPlayerIndex.Eight;
        ++index
      ) {
        var reporter = new GamePadButtonReporter(this.detectedDelegate, index);
        var method = new GamePadButtonDelegate(reporter.ButtonPressed);
        this.inputService.GetGamePad(index).ButtonPressed += method;
        this.subscribedGamePadReporters.Push(method);
      }

    }
Beispiel #18
0
 public static extern KeyDelegate SetKeyCallback(IntPtr window, KeyDelegate callback);
Beispiel #19
0
 public static extern KeyDelegate SetKeyCallback(WindowHandle window, KeyDelegate callback);
 public void RemoveKeyTriggeredEvent(KeyDelegate d)
 {
     mKeyTriggeredEvent -= d;
 }
 public void AddKeyTriggeredEvent(KeyDelegate d)
 {
     mKeyTriggeredEvent += d;
 }
 public void RemoveKeyPressedEvent(KeyDelegate d)
 {
     mKeyPressedEvent -= d;
 }
 public void AddKeyPressedEvent(KeyDelegate d)
 {
     mKeyPressedEvent += d;
 }