Beispiel #1
0
        private static ModifierKeys ConvertModifierKeysEnum(Key key)
        {
            ModifierKeys axiomKey = 0;

            switch (key)
            {
            case Key.Shift:
                axiomKey = ModifierKeys.Shift;
                break;

            case Key.Ctrl:
                axiomKey = ModifierKeys.Control;
                break;

            case Key.Alt:
                axiomKey = ModifierKeys.Alt;
                break;
            }
            return(axiomKey);
        }
Beispiel #2
0
        ///// <summary>
        /////     Clear this class input buffers (those accesible to client through one of the public methods)
        ///// </summary>
        //private void ClearInput()
        //{
        //    keyboardState = null;
        //    mouseRelX = mouseRelY = mouseRelZ = 0;
        //    mouseButtons = 0;
        //}

        ///// <summary>
        /////     Capture buffered or unbuffered mouse and/or keyboard input.
        ///// </summary>
        //private void CaptureInput()
        //{

        //    if ( useKeyboard )
        //    {
        //        if ( useKeyboardEvents )
        //        {
        //            ReadBufferedKeyboardData();
        //        }
        //        else
        //        {
        //            // TODO Grab keyboard modifiers
        //            CaptureKeyboard();
        //        }
        //    }

        //    if ( useMouse )
        //    {
        //        if ( useMouseEvents )
        //        {
        //            //TODO: implement
        //        }
        //        else
        //        {
        //            CaptureMouse();
        //        }
        //    }
        //}

        ///// <summary>
        /////		Initializes the keyboard using either immediate mode or event based input.
        ///// </summary>
        //private void InitializeKeyboard()
        //{
        //    if ( dinput == null )
        //    {
        //        dinput = new DI.DirectInput();
        //    }

        //    if ( useKeyboardEvents )
        //    {
        //        InitializeBufferedKeyboard();
        //    }
        //    else
        //    {
        //        InitializeImmediateKeyboard();
        //    }
        //}

        ///// <summary>
        /////		Initializes the mouse using either immediate mode or event based input.
        ///// </summary>
        //private void InitializeMouse()
        //{
        //    if ( dinput == null )
        //    {
        //        dinput = new DI.DirectInput();
        //    }

        //    if ( useMouseEvents )
        //    {
        //        InitializeBufferedMouse();
        //    }
        //    else
        //    {
        //        InitializeImmediateMouse();
        //    }
        //}

        ///// <summary>
        /////		Initializes DirectInput for immediate input.
        ///// </summary>
        //private void InitializeImmediateKeyboard()
        //{
        //    // Create the device.
        //    keyboardDevice = new DI.Keyboard( dinput );

        //    // grab the keyboard non-exclusively
        //    keyboardDevice.SetCooperativeLevel( winHandle, DI.CooperativeLevel.Nonexclusive | DI.CooperativeLevel.Background );

        //    // Set the data format to the keyboard pre-defined format.
        //    //keyboardDevice.SetDataFormat( DI.DeviceDataFormat.Keyboard );

        //    try
        //    {
        //        keyboardDevice.Acquire();
        //    }
        //    catch
        //    {
        //        throw new Exception( "Unable to acquire a keyboard using DirectInput." );
        //    }
        //}

        ///// <summary>
        /////		Prepares DirectInput for non-immediate input capturing.
        ///// </summary>
        //private void InitializeBufferedKeyboard()
        //{
        //    // create the device
        //    keyboardDevice = new DI.Keyboard( dinput );

        //    // Set the data format to the keyboard pre-defined format.
        //    //keyboardDevice.SetDataFormat( DI.DeviceDataFormat.Keyboard );

        //    // grab the keyboard non-exclusively
        //    keyboardDevice.SetCooperativeLevel( winHandle, DI.CooperativeLevel.Nonexclusive | DI.CooperativeLevel.Background );

        //    // set the buffer size to use for input
        //    keyboardDevice.Properties.BufferSize = BufferSize;

        //    try
        //    {
        //        keyboardDevice.Acquire();
        //    }
        //    catch
        //    {
        //        throw new Exception( "Unable to acquire a keyboard using DirectInput." );
        //    }
        //}

        ///// <summary>
        /////		Prepares DirectInput for immediate mouse input.
        ///// </summary>
        //private void InitializeImmediateMouse()
        //{
        //    // create the device
        //    mouseDevice = new DI.Mouse( dinput );

        //    //mouseDevice.Properties.AxisModeAbsolute = true;
        //    mouseDevice.Properties.AxisMode = DI.DeviceAxisMode.Relative;

        //    // set the device format so DInput knows this device is a mouse
        //    //mouseDevice.SetDataFormat( DI.DeviceDataFormat.Mouse );

        //    // set cooperation level
        //    if ( ownMouse )
        //    {
        //        mouseDevice.SetCooperativeLevel( winHandle, DI.CooperativeLevel.Exclusive | DI.CooperativeLevel.Foreground );
        //    }
        //    else
        //    {
        //        mouseDevice.SetCooperativeLevel( winHandle, DI.CooperativeLevel.Nonexclusive | DI.CooperativeLevel.Background );
        //    }

        //    // note: dont acquire yet, wait till capture
        //}

        ///// <summary>
        /////
        ///// </summary>
        //private void InitializeBufferedMouse()
        //{
        //    throw new NotImplementedException();
        //}

        ///// <summary>
        /////		Reads buffered input data when in buffered mode.
        ///// </summary>
        //private void ReadBufferedKeyboardData()
        //{
        //    // grab the collection of buffered data
        //    IEnumerable<DI.KeyboardState> bufferedData = keyboardDevice.GetBufferedData();

        //    // please tell me why this would ever come back null, rather than an empty collection...
        //    if ( bufferedData == null )
        //    {
        //        return;
        //    }

        //    foreach ( DI.KeyboardState packet in bufferedData )
        //    {
        //        foreach ( DI.Key key in packet.PressedKeys )
        //        {
        //            KeyChanged( ConvertKeyEnum( key ), true );

        //        }
        //        foreach ( DI.Key key in packet.ReleasedKeys )
        //        {

        //            KeyChanged( ConvertKeyEnum( key ), false );
        //        }

        //    }
        //}

        ///// <summary>
        /////		Captures an immediate keyboard state snapshot (for non-buffered data).
        ///// </summary>
        //private void CaptureKeyboard()
        //{
        //    keyboardState = keyboardDevice.GetCurrentState();
        //}

        ///// <summary>
        /////		Captures the mouse input based on the preffered input mode.
        ///// </summary>
        //private void CaptureMouse()
        //{
        //    mouseDevice.Acquire();

        //    // determine whether to used immediate or buffered mouse input
        //    if ( useMouseEvents )
        //    {
        //        CaptureBufferedMouse();
        //    }
        //    else
        //    {
        //        CaptureImmediateMouse();
        //    }
        //}

        ///// <summary>
        /////		Checks the buffered mouse events.
        ///// </summary>
        //private void CaptureBufferedMouse()
        //{
        //    // TODO: Implement
        //}

        ///// <summary>
        /////		Takes a snapshot of the mouse state for immediate input checking.
        ///// </summary>
        //private void CaptureImmediateMouse()
        //{
        //    // capture the current mouse state
        //    mouseState = mouseDevice.GetCurrentState();


        //    // store the updated absolute values
        //    mouseAbsX = control.PointToClient( SWF.Cursor.Position ).X;
        //    mouseAbsY = control.PointToClient( SWF.Cursor.Position ).Y;
        //    mouseAbsZ += mouseState.Z;

        //    // calc relative deviance from center
        //    mouseRelX = mouseState.X;
        //    mouseRelY = mouseState.Y;
        //    mouseRelZ = mouseState.Z;

        //    bool[] buttons = mouseState.GetButtons();

        //    // clear the flags
        //    mouseButtons = 0;

        //    for ( int i = 0; i < buttons.Length; i++ )
        //    {
        //        if ( buttons[ i ] == true )
        //        {
        //            mouseButtons |= ( 1 << i );
        //        }
        //    }
        //}

        ///// <summary>
        /////		Verifies the state of the host window and reacquires input if the window was
        /////		previously minimized and has been brought back into focus.
        ///// </summary>
        ///// <returns>True if the input devices are acquired and input capturing can proceed, false otherwise.</returns>
        //protected bool VerifyInputAcquired()
        //{
        //    // if the window is coming back from being deactivated, lets grab input again
        //    if ( window.IsActive && !lastWindowActive )
        //    {
        //        // no exceptions right now, thanks anyway
        //        //DX.DirectXException.IgnoreExceptions();

        //        // acquire and capture keyboard input
        //        if ( useKeyboard )
        //        {
        //            keyboardDevice.Acquire();
        //            CaptureKeyboard();
        //        }

        //        // acquire and capture mouse input
        //        if ( useMouse )
        //        {
        //            mouseDevice.Acquire();
        //            CaptureMouse();
        //        }

        //        // wait...i like exceptions!
        //        //DX.DirectXException.EnableExceptions();
        //    }

        //    // store the current window state
        //    lastWindowActive = window.IsActive;

        //    return lastWindowActive;
        //}

        #region Keycode Conversions

        private static Key ConvertModifierKeysEnum(ModifierKeys key)
        {
            Key dinputKey = 0;

            switch (key)
            {
            case ModifierKeys.Shift:
                dinputKey = Key.Shift;
                break;

            case ModifierKeys.Control:
                dinputKey = Key.Ctrl;
                break;

            case ModifierKeys.Alt:
                dinputKey = Key.Alt;
                break;
            }
            return(dinputKey);
        }
        ///// <summary>
        /////     Clear this class input buffers (those accesible to client through one of the public methods)
        ///// </summary>
        //private void ClearInput()
        //{
        //    keyboardState = null;
        //    mouseRelX = mouseRelY = mouseRelZ = 0;
        //    mouseButtons = 0;
        //}

        ///// <summary>
        /////     Capture buffered or unbuffered mouse and/or keyboard input.
        ///// </summary>
        //private void CaptureInput()
        //{

        //    if ( useKeyboard )
        //    {
        //        if ( useKeyboardEvents )
        //        {
        //            ReadBufferedKeyboardData();
        //        }
        //        else
        //        {
        //            // TODO Grab keyboard modifiers
        //            CaptureKeyboard();
        //        }
        //    }

        //    if ( useMouse )
        //    {
        //        if ( useMouseEvents )
        //        {
        //            //TODO: implement
        //        }
        //        else
        //        {
        //            CaptureMouse();
        //        }
        //    }
        //}

        ///// <summary>
        /////		Initializes the keyboard using either immediate mode or event based input.
        ///// </summary>
        //private void InitializeKeyboard()
        //{
        //    if ( dinput == null )
        //    {
        //        dinput = new DI.DirectInput();
        //    }

        //    if ( useKeyboardEvents )
        //    {
        //        InitializeBufferedKeyboard();
        //    }
        //    else
        //    {
        //        InitializeImmediateKeyboard();
        //    }
        //}

        ///// <summary>
        /////		Initializes the mouse using either immediate mode or event based input.
        ///// </summary>
        //private void InitializeMouse()
        //{
        //    if ( dinput == null )
        //    {
        //        dinput = new DI.DirectInput();
        //    }

        //    if ( useMouseEvents )
        //    {
        //        InitializeBufferedMouse();
        //    }
        //    else
        //    {
        //        InitializeImmediateMouse();
        //    }
        //}

        ///// <summary>
        /////		Initializes DirectInput for immediate input.
        ///// </summary>
        //private void InitializeImmediateKeyboard()
        //{
        //    // Create the device.
        //    keyboardDevice = new DI.Keyboard( dinput );

        //    // grab the keyboard non-exclusively
        //    keyboardDevice.SetCooperativeLevel( winHandle, DI.CooperativeLevel.Nonexclusive | DI.CooperativeLevel.Background );

        //    // Set the data format to the keyboard pre-defined format.
        //    //keyboardDevice.SetDataFormat( DI.DeviceDataFormat.Keyboard );

        //    try
        //    {
        //        keyboardDevice.Acquire();
        //    }
        //    catch
        //    {
        //        throw new Exception( "Unable to acquire a keyboard using DirectInput." );
        //    }
        //}

        ///// <summary>
        /////		Prepares DirectInput for non-immediate input capturing.
        ///// </summary>
        //private void InitializeBufferedKeyboard()
        //{
        //    // create the device
        //    keyboardDevice = new DI.Keyboard( dinput );

        //    // Set the data format to the keyboard pre-defined format.
        //    //keyboardDevice.SetDataFormat( DI.DeviceDataFormat.Keyboard );

        //    // grab the keyboard non-exclusively
        //    keyboardDevice.SetCooperativeLevel( winHandle, DI.CooperativeLevel.Nonexclusive | DI.CooperativeLevel.Background );

        //    // set the buffer size to use for input
        //    keyboardDevice.Properties.BufferSize = BufferSize;

        //    try
        //    {
        //        keyboardDevice.Acquire();
        //    }
        //    catch
        //    {
        //        throw new Exception( "Unable to acquire a keyboard using DirectInput." );
        //    }
        //}

        ///// <summary>
        /////		Prepares DirectInput for immediate mouse input.
        ///// </summary>
        //private void InitializeImmediateMouse()
        //{
        //    // create the device
        //    mouseDevice = new DI.Mouse( dinput );

        //    //mouseDevice.Properties.AxisModeAbsolute = true;
        //    mouseDevice.Properties.AxisMode = DI.DeviceAxisMode.Relative;

        //    // set the device format so DInput knows this device is a mouse
        //    //mouseDevice.SetDataFormat( DI.DeviceDataFormat.Mouse );

        //    // set cooperation level
        //    if ( ownMouse )
        //    {
        //        mouseDevice.SetCooperativeLevel( winHandle, DI.CooperativeLevel.Exclusive | DI.CooperativeLevel.Foreground );
        //    }
        //    else
        //    {
        //        mouseDevice.SetCooperativeLevel( winHandle, DI.CooperativeLevel.Nonexclusive | DI.CooperativeLevel.Background );
        //    }

        //    // note: dont acquire yet, wait till capture
        //}

        ///// <summary>
        /////
        ///// </summary>
        //private void InitializeBufferedMouse()
        //{
        //    throw new NotImplementedException();
        //}

        ///// <summary>
        /////		Reads buffered input data when in buffered mode.
        ///// </summary>
        //private void ReadBufferedKeyboardData()
        //{
        //    // grab the collection of buffered data
        //    IEnumerable<DI.KeyboardState> bufferedData = keyboardDevice.GetBufferedData();

        //    // please tell me why this would ever come back null, rather than an empty collection...
        //    if ( bufferedData == null )
        //    {
        //        return;
        //    }

        //    foreach ( DI.KeyboardState packet in bufferedData )
        //    {
        //        foreach ( DI.Key key in packet.PressedKeys )
        //        {
        //            KeyChanged( ConvertKeyEnum( key ), true );

        //        }
        //        foreach ( DI.Key key in packet.ReleasedKeys )
        //        {

        //            KeyChanged( ConvertKeyEnum( key ), false );
        //        }

        //    }
        //}

        ///// <summary>
        /////		Captures an immediate keyboard state snapshot (for non-buffered data).
        ///// </summary>
        //private void CaptureKeyboard()
        //{
        //    keyboardState = keyboardDevice.GetCurrentState();
        //}

        ///// <summary>
        /////		Captures the mouse input based on the preffered input mode.
        ///// </summary>
        //private void CaptureMouse()
        //{
        //    mouseDevice.Acquire();

        //    // determine whether to used immediate or buffered mouse input
        //    if ( useMouseEvents )
        //    {
        //        CaptureBufferedMouse();
        //    }
        //    else
        //    {
        //        CaptureImmediateMouse();
        //    }
        //}

        ///// <summary>
        /////		Checks the buffered mouse events.
        ///// </summary>
        //private void CaptureBufferedMouse()
        //{
        //    // TODO: Implement
        //}

        ///// <summary>
        /////		Takes a snapshot of the mouse state for immediate input checking.
        ///// </summary>
        //private void CaptureImmediateMouse()
        //{
        //    // capture the current mouse state
        //    mouseState = mouseDevice.GetCurrentState();


        //    // store the updated absolute values
        //    mouseAbsX = control.PointToClient( SWF.Cursor.Position ).X;
        //    mouseAbsY = control.PointToClient( SWF.Cursor.Position ).Y;
        //    mouseAbsZ += mouseState.Z;

        //    // calc relative deviance from center
        //    mouseRelX = mouseState.X;
        //    mouseRelY = mouseState.Y;
        //    mouseRelZ = mouseState.Z;

        //    bool[] buttons = mouseState.GetButtons();

        //    // clear the flags
        //    mouseButtons = 0;

        //    for ( int i = 0; i < buttons.Length; i++ )
        //    {
        //        if ( buttons[ i ] == true )
        //        {
        //            mouseButtons |= ( 1 << i );
        //        }
        //    }
        //}

        ///// <summary>
        /////		Verifies the state of the host window and reacquires input if the window was
        /////		previously minimized and has been brought back into focus.
        ///// </summary>
        ///// <returns>True if the input devices are acquired and input capturing can proceed, false otherwise.</returns>
        //protected bool VerifyInputAcquired()
        //{
        //    // if the window is coming back from being deactivated, lets grab input again
        //    if ( window.IsActive && !lastWindowActive )
        //    {
        //        // no exceptions right now, thanks anyway
        //        //DX.DirectXException.IgnoreExceptions();

        //        // acquire and capture keyboard input
        //        if ( useKeyboard )
        //        {
        //            keyboardDevice.Acquire();
        //            CaptureKeyboard();
        //        }

        //        // acquire and capture mouse input
        //        if ( useMouse )
        //        {
        //            mouseDevice.Acquire();
        //            CaptureMouse();
        //        }

        //        // wait...i like exceptions!
        //        //DX.DirectXException.EnableExceptions();
        //    }

        //    // store the current window state
        //    lastWindowActive = window.IsActive;

        //    return lastWindowActive;
        //}

        #region Keycode Conversions

        private static Key ConvertModifierKeysEnum( ModifierKeys key )
        {
            Key dinputKey = 0;
            switch ( key )
            {
                case ModifierKeys.Shift:
                    dinputKey = Key.Shift;
                    break;
                case ModifierKeys.Control:
                    dinputKey = Key.Ctrl;
                    break;
                case ModifierKeys.Alt:
                    dinputKey = Key.Alt;
                    break;
            }
            return dinputKey;
        }