public NesVSUnisystemDIPKeyboardConnection(IntPtr handle, IInputSettingsVSUnisystemDIP settings) { DirectInput di = new DirectInput(); keyboard = new Keyboard(di); keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); if (settings.CreditServiceButton != "") CreditServiceButton = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.CreditServiceButton); if (settings.DIPSwitch1 != "") DIPSwitch1 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch1); if (settings.DIPSwitch2 != "") DIPSwitch2 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch2); if (settings.DIPSwitch3 != "") DIPSwitch3 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch3); if (settings.DIPSwitch4 != "") DIPSwitch4 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch4); if (settings.DIPSwitch5 != "") DIPSwitch5 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch5); if (settings.DIPSwitch6 != "") DIPSwitch6 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch6); if (settings.DIPSwitch7 != "") DIPSwitch7 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch7); if (settings.DIPSwitch8 != "") DIPSwitch8 = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.DIPSwitch8); if (settings.CreditLeftCoinSlot != "") CreditLeftCoinSlot = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.CreditLeftCoinSlot); if (settings.CreditRightCoinSlot != "") CreditRightCoinSlot = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.CreditRightCoinSlot); NesEmu.EMUShutdown += NesEmu_EMUShutdown; }
public NesJoypadPcKeyboardConnection(IntPtr handle, IInputSettingsJoypad settings) { DirectInput di = new DirectInput(); keyboard = new Keyboard(di); keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); if (settings.ButtonUp != "") KeyUp = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonUp); if (settings.ButtonDown != "") KeyDown = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonDown); if (settings.ButtonLeft != "") KeyLeft = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonLeft); if (settings.ButtonRight != "") KeyRight = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonRight); if (settings.ButtonStart != "") KeyStart = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonStart); if (settings.ButtonSelect != "") KeySelect = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonSelect); if (settings.ButtonA != "") KeyA = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonA); if (settings.ButtonB != "") KeyB = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonB); if (settings.ButtonTurboA != "") KeyTurboA = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonTurboA); if (settings.ButtonTurboB != "") KeyTurboB = (SlimDX.DirectInput.Key)Enum.Parse(typeof(SlimDX.DirectInput.Key), settings.ButtonTurboB); }
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(Game game, IntPtr handle) : base(game, -10000) { _directInput = new DirectInput(); _keyboard = new Keyboard(_directInput); _keyboard.Properties.BufferSize = 256; _keyboard.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); _mouse = new Mouse(_directInput); _mouse.Properties.AxisMode = DeviceAxisMode.Relative; _mouse.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); var devices = _directInput.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices); if (devices.Count > 0) { _joystick = new Joystick(_directInput, devices[0].InstanceGuid); _joystick.SetCooperativeLevel(handle, CooperativeLevel.Background | CooperativeLevel.NonExclusive); } }
public FormKey(SlimDX.DirectInput.DeviceType type, string deviceGuid, string keyName) { this.deviceType = type; InitializeComponent(); DirectInput di = new DirectInput(); switch (type) { case SlimDX.DirectInput.DeviceType.Keyboard: { keyboard = new Keyboard(di); keyboard.SetCooperativeLevel(this.Handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); break; } case SlimDX.DirectInput.DeviceType.Joystick: { joystick = new Joystick(di, Guid.Parse(deviceGuid)); joystick.SetCooperativeLevel(this.Handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); break; } case SlimDX.DirectInput.DeviceType.Other: { switch (deviceGuid) { case "x-controller-1": x_controller = new Controller(UserIndex.One); break; case "x-controller-2": x_controller = new Controller(UserIndex.Two); break; case "x-controller-3": x_controller = new Controller(UserIndex.Three); break; case "x-controller-4": x_controller = new Controller(UserIndex.Four); break; } break; } } timer_hold.Start(); label1.Text = string.Format(Program.ResourceManager.GetString("Text_PressAKeyFor") + " [{0}]", keyName); stopTimer = 10; label_cancel.Text = string.Format(Program.ResourceManager.GetString("Status_CancelIn") + " {0} " + Program.ResourceManager.GetString("Status_Seconds"), stopTimer); timer2.Start(); this.Select(); }
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; } } }
public InputManager(IntPtr handle) { _devices = new List<InputDevice>(); var di = new DirectInput(); foreach (var device in di.GetDevices(DeviceClass.All, DeviceEnumerationFlags.AttachedOnly)) { if ((device.Type & DeviceType.Keyboard) == DeviceType.Keyboard) { var keyboard = new Keyboard(di); keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); _devices.Add(new InputDevice(keyboard)); } else if ((device.Type & DeviceType.Joystick) == DeviceType.Joystick) { var joystick = new Joystick(di, device.InstanceGuid); joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); _devices.Add(new InputDevice(joystick)); } } }
private void InitializeDevices() { var handle = WrenCore.WindowHandle; _joysticks = new List<Joystick>(); DirectInput di = new DirectInput(); foreach (var device in di.GetDevices(DeviceClass.All, DeviceEnumerationFlags.AttachedOnly)) { if ((device.Type & DeviceType.Keyboard) == DeviceType.Keyboard) { Keyboard keyboard = new Keyboard(di); keyboard.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); _keyboard = keyboard; } else if ((device.Type & DeviceType.Joystick) == DeviceType.Joystick) { Joystick joystick = new Joystick(di, device.InstanceGuid); joystick.SetCooperativeLevel(handle, CooperativeLevel.Nonexclusive | CooperativeLevel.Foreground); _joysticks.Add(joystick); } } }
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> /// 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; }
/// <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(); }