public Input() { _directInput = new DirectInput(); try { Result result; _keyboard = new Keyboard(_directInput); IntPtr handle = Engine.GameEngine.Window; if ((result = _keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Background)) != ResultCode.Success) { Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(result.Description, result.Name, "keyboard cooperation")); } _mouse = new Mouse(_directInput); if ((result = _mouse.SetCooperativeLevel(handle, CooperativeLevel.Foreground | CooperativeLevel.Nonexclusive)) != ResultCode.Success) { Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(result.Description, result.Name, "mouse cooperation")); } if ((result = _keyboard.Acquire()) != ResultCode.Success) { Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(result.Description, result.Name, "keyboard acquire")); } if ((result = _mouse.Acquire()) != ResultCode.Success) { Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(result.Description, result.Name, "mouse acquire")); } Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData("worked", "worked", "worked")); } catch (DirectInputException e) { Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(e.Message, e.Source, e.StackTrace)); } catch (Exception e) { Engine.GameEngine.Exception.Exceptions.Add(new ExceptionData(e.Message, e.Source, e.StackTrace)); } finally { Dispose(); } }
public DX_Keyboard() { DirectInput dinput = new DirectInput(); keyboard = new Keyboard(dinput); keyboard.SetCooperativeLevel(Globals.l2net_home, CooperativeLevel.Nonexclusive | CooperativeLevel.Background); keyboard.Acquire(); dx_keyboard_thread = new System.Threading.Thread(new System.Threading.ThreadStart(DX_KeyboardEngine)); dx_keyboard_thread.IsBackground = true; dx_keyboard_thread.Start(); }
void CreateDevice() { // make sure that DirectInput has been initialized DirectInput dinput = new DirectInput(); // build up cooperative flags CooperativeLevel cooperativeLevel; if (exclusiveRadio.Checked) cooperativeLevel = CooperativeLevel.Exclusive; else cooperativeLevel = CooperativeLevel.Nonexclusive; if (foregroundRadio.Checked) cooperativeLevel |= CooperativeLevel.Foreground; else cooperativeLevel |= CooperativeLevel.Background; if (disableCheck.Checked) cooperativeLevel |= CooperativeLevel.NoWinKey; // create the device try { keyboard = new Keyboard(dinput); keyboard.SetCooperativeLevel(this, cooperativeLevel); } catch (DirectInputException e) { MessageBox.Show(e.Message); return; } if (!immediateRadio.Checked) { // since we want to use buffered data, we need to tell DirectInput // to set up a buffer for the data keyboard.Properties.BufferSize = 8; } // acquire the device keyboard.Acquire(); // set the timer to go off 12 times a second to read input // NOTE: Normally applications would read this much faster. // This rate is for demonstration purposes only. timer.Interval = 1000 / 12; timer.Start(); }
public Input(Form window) { _window = window; _di = new DirectInput(); _keyboard = new Keyboard(_di); //_keyboard.SetCooperativeLevel(_window.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive); _keyboard.Acquire(); Log.Info("Keyboard aquired"); _mouse = new Mouse(_di); //_mouse.SetCooperativeLevel(_window.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive); _mouse.Acquire(); Log.Info("Mouse aquired"); _pressStamp = 0; }
public void Reinitialize_Keyboard(IntPtr window_handle) { if (critical_failure == false) { try { Uninitialize_Keyboard(); dinput = new DirectInput(); keyb = new Keyboard(dinput); keyb.SetCooperativeLevel(window_handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive); keyb.Acquire(); setup_keys(); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.ToString(), "Error!", System.Windows.Forms.MessageBoxButtons.OK); return; } } }
private void Initialize_Keyboard(IntPtr window_handle) { try { dinput = new DirectInput(); keyb = new Keyboard(dinput); keyb.SetCooperativeLevel(window_handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive); keyb.Acquire(); setup_keys(); } catch { System.Windows.Forms.MessageBox.Show("A failure has been detected during DirectInput initialization, please contact the author for assistance.", "Error!", System.Windows.Forms.MessageBoxButtons.OK); critical_failure = true; } }
public override Action Start() { IntPtr handle = Process.GetCurrentProcess().MainWindowHandle; KeyboardDevice = new 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); setKeyPressedStrategy = new SetPressedStrategy(KeyDown, KeyUp); getKeyPressedStrategy = new GetPressedStrategy<int>(IsKeyDown); OnStarted(this, new EventArgs()); return null; }
/// <summary> /// The main entry point for the application. /// </summary> //[STAThread] static void MainForKeyboard() { // Initialize DirectInput var directInput = new DirectInput(); // Instantiate the joystick var keyboard = new Keyboard(directInput); // Acquire the joystick keyboard.Properties.BufferSize = 128; keyboard.Acquire(); // Poll events from joystick while (true) { keyboard.Poll(); var datas = keyboard.GetBufferedData(); foreach (var state in datas) Console.WriteLine(state); } }
/// <summary> /// Initialize the input. /// </summary> public static void ModuleInit() { directInput = new DirectInput(); keyboard = new Keyboard(directInput); keyboard.SetCooperativeLevel(Scene.Instance.GraphicsEngine.Form, CooperativeLevel.Nonexclusive | CooperativeLevel.Background); keyboard.Acquire(); mouse = new Mouse(directInput); mouse.SetCooperativeLevel(Scene.Instance.GraphicsEngine.Form, CooperativeLevel.Nonexclusive | CooperativeLevel.Background); mouse.Acquire(); s_lastFrameState = keyboard.GetCurrentState(); s_thisState = s_lastFrameState; s_lastFrameMouseState = mouse.GetCurrentState(); s_thisMouseState = s_lastFrameMouseState; }
public Camera(Device device, float aspectRatio) { _globals = new Constants(); _aspect = aspectRatio; _fov = 1.3f; View = Matrix.LookAtLH(new Vector3(0, 0, -20f), Vector3.Zero, Vector3.UnitY); SetPerspective(); _device = device; //Projection = Matrix.PerspectiveFovLH(_fov, aspectRatio, 0.0001f, 100000); //Projection = Matrix.OrthoLH(10 * _aspect, 10, 0.0001f, 100000); var data = new DataStream(Marshal.SizeOf(typeof(Constants)), true, true); data.Write(_globals); data.Position = 0; _globalConstants = new Buffer(device, //Device data, //Stream Marshal.SizeOf(typeof(Constants)), // Size ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 64); device.ImmediateContext.PixelShader.SetConstantBuffer(_globalConstants, 0); DirectInput input = new DirectInput(); keyboard = new Keyboard(input); mouse = new Mouse(input); keyboard.Acquire(); mouse.Acquire(); lastMouseX = Cursor.Position.X; lastMouseY = Cursor.Position.Y; ResetCamera(); }
/// <summary> /// Initialize input methods and /// setup it's settings /// </summary> /// <param name="_control"></param> public void SetupInput(Control _control) { InputControl = _control; /// make sure that DirectInput has been initialized DirectInput dinput = new DirectInput(); /// create the device try { g_keyboard = new Keyboard(dinput); g_keyboard.Properties.BufferSize = 256; g_keyboard.SetCooperativeLevel( _control, CooperativeLevel.Foreground | CooperativeLevel.NonExclusive | CooperativeLevel.NoWinKey); g_keyboard.Acquire(); } catch (MarshalDirectiveException e) { MessageBox.Show(e.Message); return; } /// acquire the device Release_KeyBoard(); /// setup Mouse dinput = new DirectInput(); try { g_mouse = new Mouse(dinput); g_mouse.SetCooperativeLevel(_control, CooperativeLevel.Exclusive | CooperativeLevel.Foreground); } catch (MarshalDirectiveException e) { MessageBox.Show(e.Message); return; } /// since we want to use buffered data, /// we need to tell DirectInput /// to set up a buffer for the data g_mouse.Properties.BufferSize = 10; /// acquire the device and release to OS Release_Mouse(); }
public void setDevice( int ID , string type) { if (jmDevice != null) { jmDevice.Dispose(); while (jmDevice.IsDisposed == false) ; } foreach (Devices d in devices) if (d.type== type && (d.id == ID) ) deviceGuid = d.guid; //start up the device. if (type == "Gamepad" || type == "Joystick" || type == "Mouse") { jmDevice = new Joystick( directInput, deviceGuid ); jmDeviceState = new JoystickState(); jmDevice.Acquire(); } if ( type == "Keyboard" ) { //start up the device. kDevice = new Keyboard( directInput); kDeviceState = new KeyboardState(); kDevice.Acquire(); } }