Esempio n. 1
1
 private void CreateNativeKeyboard()
 {
     nativeState = new DInput.KeyboardState();
     directInput = new DInput.DirectInput();
     nativeKeyboard = new DInput.Keyboard(directInput);
     nativeKeyboard.SetCooperativeLevel(windowHandle,
         DInput.CooperativeLevel.NonExclusive | DInput.CooperativeLevel.Background);
     nativeKeyboard.Acquire();
 }
Esempio n. 2
0
        /// <summary>
        /// ctor and init
        /// </summary>
        /// <param name="device">A DXInput device</param>
        /// <param name="hwnd">The WinHandle of the main window</param>
        public KeyboardCls(SharpDX.DirectInput.Keyboard device, Control hwnd)
        {
            log.DebugFormat("KeyboardCls ctor - Entry with {0}", device.Information.ProductName);

            m_device  = device;
            m_hwnd    = hwnd;
            Activated = false;

            // Set BufferSize in order to use buffered data.
            m_device.Properties.BufferSize = 128;

            log.Debug("Get KBD Object");
            try {
                // Set the data format to the c_dfDIJoystick pre-defined format.
                //m_device.SetDataFormat( DeviceDataFormat.Joystick );
                // Set the cooperative level for the device.
                m_device.SetCooperativeLevel(m_hwnd, CooperativeLevel.NonExclusive | CooperativeLevel.Background);
                // Enumerate all the objects on the device.
            }
            catch (Exception ex) {
                log.Error("Get Keyboard Object failed", ex);
            }

            KeyboardCls.RegisteredDevices++;

            Activated = true;
        }
Esempio n. 3
0
        public override Action Start()
        {
            IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;

            KeyboardDevice = new SharpDX.DirectInput.Keyboard(DirectInputInstance);
            if (KeyboardDevice == null)
            {
                throw new Exception("Failed to create keyboard device");
            }

            KeyboardDevice.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
            KeyboardDevice.Acquire();

            KeyboardDevice.GetCurrentState(ref KeyState);


            mouseDevice = new SharpDX.DirectInput.Mouse(DirectInputInstance);
            if (mouseDevice == null)
            {
                throw new Exception("Failed to create mouse device");
            }

            mouseDevice.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive);
            mouseDevice.Properties.AxisMode = DeviceAxisMode.Relative;   // Get delta values
            mouseDevice.Acquire();



            getPressedStrategy = new GetPressedStrategy <int>(IsDown);
            setPressedStrategy = new SetPressedStrategy <int>(KeyOrButtonDown, KeyOrButtonUp);

            OnStarted(this, new EventArgs());
            return(null);
        }
		private void CreateNativeKeyboard()
		{
			nativeState = new DInput.KeyboardState();
			directInput = new DInput.DirectInput();
			nativeKeyboard = new DInput.Keyboard(directInput);
			if (window.IsWindowsFormAndNotJustAPanel)
				nativeKeyboard.SetCooperativeLevel(window.Handle,
					DInput.CooperativeLevel.NonExclusive | DInput.CooperativeLevel.Background);
			nativeKeyboard.Acquire();
		}
 private void CreateNativeKeyboard()
 {
     nativeState    = new DInput.KeyboardState();
     directInput    = new DInput.DirectInput();
     nativeKeyboard = new DInput.Keyboard(directInput);
     if (window.IsWindowsFormAndNotJustAPanel)
     {
         nativeKeyboard.SetCooperativeLevel(window.Handle,
                                            DInput.CooperativeLevel.NonExclusive | DInput.CooperativeLevel.Background);
     }
     nativeKeyboard.Acquire();
 }
Esempio n. 6
0
        private void _initializeInputs()
        {
            Console.Write("Initializing inputs... ");

            _directInput = ToDispose<DirectInput>(new DirectInput());

            _dKeyboard = ToDispose<DKeyboard>(new DKeyboard(_directInput));
            _dKeyboard.Properties.BufferSize = 256;
            _dKeyboard.SetCooperativeLevel(_form, CooperativeLevel.Foreground | CooperativeLevel.Exclusive);
            Keyboard = new Keyboard(_dKeyboard);

            _dMouse = ToDispose<DMouse>(new DMouse(_directInput));
            _dMouse.Properties.AxisMode = DeviceAxisMode.Relative;
            _dMouse.SetCooperativeLevel(_form, CooperativeLevel.Foreground | CooperativeLevel.NonExclusive);
            Mouse = new Mouse(_form, _dMouse);
            Console.WriteLine("done.");
        }
        /// <summary>Initialises the keyboard.</summary>
        /// <param name="control">The control to associate with DirectInput.</param>
        private void InitialiseKeyboard(WF.Control control)
        {
            // From idlibc.c
            _keyToScanCode = new int[256];
            _keyToScanCode[(int) DI.Key.Escape] = 0x01;
            _keyToScanCode[(int) DI.Key.Space] = 0x39;
            _keyToScanCode[(int) DI.Key.Back] = 0x0e;
            _keyToScanCode[(int) DI.Key.Tab] = 0x0f;
            _keyToScanCode[(int) DI.Key.LeftControl] = 0x1d;
            _keyToScanCode[(int) DI.Key.LeftShift] = 0x2a;
            _keyToScanCode[(int) DI.Key.Capital] = 0x3a;
            _keyToScanCode[(int) DI.Key.F1] = 0x3b;
            _keyToScanCode[(int) DI.Key.F2] = 0x3c;
            _keyToScanCode[(int) DI.Key.F3] = 0x3d;
            _keyToScanCode[(int) DI.Key.F4] = 0x3e;
            _keyToScanCode[(int) DI.Key.F5] = 0x3f;
            _keyToScanCode[(int) DI.Key.F6] = 0x40;
            _keyToScanCode[(int) DI.Key.F7] = 0x41;
            _keyToScanCode[(int) DI.Key.F8] = 0x42;
            _keyToScanCode[(int) DI.Key.F9] = 0x43;
            _keyToScanCode[(int) DI.Key.F10] = 0x44;
            _keyToScanCode[(int) DI.Key.F11] = 0x57;
            _keyToScanCode[(int) DI.Key.F12] = 0x58;
            _keyToScanCode[(int) DI.Key.ScrollLock] = 0x46;
            _keyToScanCode[(int) DI.Key.Return] = 0x1c;
            _keyToScanCode[(int) DI.Key.RightShift] = 0x36;
            _keyToScanCode[(int) DI.Key.PrintScreen] = 0x37;
            _keyToScanCode[(int) DI.Key.LeftAlt] = 0x38;
            _keyToScanCode[(int) DI.Key.Home] = 0x47;
            _keyToScanCode[(int) DI.Key.PageUp] = 0x49;
            _keyToScanCode[(int) DI.Key.End] = 0x4f;
            _keyToScanCode[(int) DI.Key.PageDown] = 0x51;
            _keyToScanCode[(int) DI.Key.Insert] = 0x52;
            _keyToScanCode[(int) DI.Key.Delete] = 0x53;
            _keyToScanCode[(int) DI.Key.NumberLock] = 0x45;
            _keyToScanCode[(int) DI.Key.Up] = 0x48;
            _keyToScanCode[(int) DI.Key.Down] = 0x50;
            _keyToScanCode[(int) DI.Key.Left] = 0x4b;
            _keyToScanCode[(int) DI.Key.Right] = 0x4d;
            _keyToScanCode[(int) DI.Key.D1] = 0x02;
            _keyToScanCode[(int) DI.Key.D2] = 0x03;
            _keyToScanCode[(int) DI.Key.D3] = 0x04;
            _keyToScanCode[(int) DI.Key.D4] = 0x05;
            _keyToScanCode[(int) DI.Key.D5] = 0x06;
            _keyToScanCode[(int) DI.Key.D6] = 0x07;
            _keyToScanCode[(int) DI.Key.D7] = 0x08;
            _keyToScanCode[(int) DI.Key.D8] = 0x09;
            _keyToScanCode[(int) DI.Key.D9] = 0x0a;
            _keyToScanCode[(int) DI.Key.D0] = 0x0b;
            _keyToScanCode[(int) DI.Key.Minus] = 0x0c;
            _keyToScanCode[(int) DI.Key.Equals] = 0x0d;
            _keyToScanCode[(int) DI.Key.Q] = 0x10;
            _keyToScanCode[(int) DI.Key.W] = 0x11;
            _keyToScanCode[(int) DI.Key.E] = 0x12;
            _keyToScanCode[(int) DI.Key.R] = 0x13;
            _keyToScanCode[(int) DI.Key.T] = 0x14;
            _keyToScanCode[(int) DI.Key.Y] = 0x15;
            _keyToScanCode[(int) DI.Key.U] = 0x16;
            _keyToScanCode[(int) DI.Key.I] = 0x17;
            _keyToScanCode[(int) DI.Key.O] = 0x18;
            _keyToScanCode[(int) DI.Key.P] = 0x19;
            _keyToScanCode[(int) DI.Key.LeftBracket] = 0x1a;
            _keyToScanCode[(int) DI.Key.RightBracket] = 0x1b;
            //_keyToScanCode[(int) DI.Key.OemPipe] = 0x1c; // TODO
            _keyToScanCode[(int) DI.Key.A] = 0x1e;
            _keyToScanCode[(int) DI.Key.S] = 0x1f;
            _keyToScanCode[(int) DI.Key.D] = 0x20;
            _keyToScanCode[(int) DI.Key.F] = 0x21;
            _keyToScanCode[(int) DI.Key.G] = 0x22;
            _keyToScanCode[(int) DI.Key.H] = 0x23;
            _keyToScanCode[(int) DI.Key.J] = 0x24;
            _keyToScanCode[(int) DI.Key.K] = 0x25;
            _keyToScanCode[(int) DI.Key.L] = 0x26;
            _keyToScanCode[(int) DI.Key.Semicolon] = 0x27;
            //_keyToScanCode[(int) DI.Key.OemQuotes] = 0x28; // TODO
            _keyToScanCode[(int) DI.Key.Z] = 0x2c;
            _keyToScanCode[(int) DI.Key.X] = 0x2d;
            _keyToScanCode[(int) DI.Key.C] = 0x2e;
            _keyToScanCode[(int) DI.Key.V] = 0x2f;
            _keyToScanCode[(int) DI.Key.B] = 0x30;
            _keyToScanCode[(int) DI.Key.N] = 0x31;
            _keyToScanCode[(int) DI.Key.M] = 0x32;
            _keyToScanCode[(int) DI.Key.Comma] = 0x33;
            _keyToScanCode[(int) DI.Key.Period] = 0x34;
            // see idlibc.chartable for other keys

            _keyboard = new DI.Keyboard(_directInput);
            _keyboard.SetCooperativeLevel(control, DI.CooperativeLevel.NonExclusive | DI.CooperativeLevel.Background);
            _keyboard.Acquire();

            _keyboardState = _keyboard.GetCurrentState();
        }