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(); }
public Game() { renderForm = new RenderForm("D3D11 Planets"); renderForm.MouseMove += (object sender, System.Windows.Forms.MouseEventArgs e) => { realMousePos = new Vector2(e.Location.X, e.Location.Y); }; renderForm.WindowState = System.Windows.Forms.FormWindowState.Maximized; renderForm.AllowUserResizing = true; renderForm.ClientSizeChanged += (object sender, EventArgs e) => { resizePending = true; }; DInput.DirectInput directInput = new DInput.DirectInput(); keyboard = new DInput.Keyboard(directInput); mouse = new DInput.Mouse(directInput); keyboard.Acquire(); mouse.Acquire(); renderer = new Renderer(this, renderForm); Shaders.Load(renderer.Device, renderer.Context); Resources.Load(renderer.Device); Initialize(); }
public SpriteWindow() { Keyboard = new DirectInput.Keyboard(DirectInput); Keyboard.Acquire(); Mouse = new DirectInput.Mouse(DirectInput); Mouse.Acquire(); }
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); }
public Keyboard(DirectInput DirectInput) { _Keyboard = new SharpDX.DirectInput.Keyboard(DirectInput); _Keyboard.Acquire(); UpdateKeyboardState(); UpdateKeyboardState(); }
internal Keyboard() { DirectInputKeyboard = new DI.Keyboard(new DI.DirectInput()); DirectInputKeyboard.Properties.BufferSize = 128; DirectInputKeyboard.Acquire(); KeyboardInstance = this; }
/// <summary> /// HlavnĂ konstruktor. /// </summary> /// <param name="window">HernĂ okno.</param> public Keyboard(GlibWindow window) : base(window) { keyboard = new KeyboardDirect(Input); keyboard.Properties.BufferSize = 128; keyboard.Acquire(); state = new KeyboardState(); }
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(); }
public InputDeviceKeyboard(DirectInput di, DeviceInstance d) { // those silly foreign people call keyboard something other than it in english, so we need to fix it to english ksi = new InputDeviceIdentity() { Instanceguid = d.InstanceGuid, Productguid = d.ProductGuid, Name = "Keyboard" }; keyboard = new Keyboard(di); keyboard.Properties.BufferSize = 128; keyboard.SetNotification(eventhandle); keyboard.Acquire(); }
public int _InitializeKeyboard() { _InitializeKeyboardAuth = 1; try { directInput = new DirectInput(); _Keyboard = new SharpDX.DirectInput.Keyboard(directInput); _Keyboard.Properties.BufferSize = 128; _Keyboard.Acquire(); } catch { _InitializeKeyboardAuth = 0; } return(_InitializeKeyboardAuth); }
private Keyboard StartKeyboard() { var dirInput = new SharpDX.DirectInput.DirectInput(); var allDevices = dirInput.GetDevices(); Keyboard keyboard = null; foreach (var item in allDevices) { if (SharpDX.DirectInput.DeviceType.Keyboard == item.Type) { keyboard = new SharpDX.DirectInput.Keyboard(dirInput); keyboard.Acquire(); } } return(keyboard); }
/// <summary> /// Collect the current data from the device /// </summary> public override void GetData( ) { // Make sure there is a valid device. if (null == m_device) { return; } // Poll the device for info. try { m_device.Poll( ); } catch (SharpDXException e) { if ((e.ResultCode == ResultCode.NotAcquired) || (e.ResultCode == ResultCode.InputLost)) { // Check to see if either the app needs to acquire the device, or // if the app lost the device to another process. try { // Acquire the device - if the (main)window is active if (Activated) { m_device.Acquire( ); } } catch (SharpDXException) { // Failed to acquire the device. This could be because the app doesn't have focus. return; // EXIT unaquired } } else { log.Error("Unexpected Poll Exception", e); return; // EXIT see ex code } } // Get the state of the device - retaining the previous state to find the lates change try { m_state = m_device.GetCurrentState( ); } // Catch any exceptions. None will be handled here, // any device re-aquisition will be handled above. catch (SharpDXException) { return; } }
public bool ReadKeyboard() { var resultCode = SharpDX.DirectInput.ResultCode.Ok; try { _Keyboard.GetCurrentState(ref _KeyboardState); } catch (SharpDX.SharpDXException ex) { resultCode = ex.Descriptor; } catch (Exception ex) { MainWindow.MessageBox((IntPtr)0, "cannot get keyboard info 00: " + ex.ToString() + "", "Oculus error", 0); return(false); } if (resultCode == SharpDX.DirectInput.ResultCode.InputLost || resultCode == SharpDX.DirectInput.ResultCode.NotAcquired) { try { _Keyboard.Acquire(); } catch (Exception ex) { MainWindow.MessageBox((IntPtr)0, "cannot get keyboard info 01: " + ex.ToString() + "", "Oculus error", 0); } return(true); } if (resultCode == SharpDX.DirectInput.ResultCode.Ok) { return(true); } return(false); }
public void KeyBoardStart() { var dirInput = new SharpDX.DirectInput.DirectInput(); var allDevices = dirInput.GetDevices(); foreach (var item in allDevices) { if (SharpDX.DirectInput.DeviceType.Keyboard == item.Type) { curKeyBoard = new SharpDX.DirectInput.Keyboard(dirInput); curKeyBoard.Acquire(); } } while (true) { Thread.Sleep(100); var curKeyboardState = curKeyBoard.GetCurrentState(); Key curPressedKey = new Key();; if (curKeyboardState.PressedKeys.Count() > 0) { curPressedKey = curKeyboardState.PressedKeys[0]; } if (curPressedKey == SharpDX.DirectInput.Key.O || curPressedKey == SharpDX.DirectInput.Key.P) { var dir = curPressedKey == SharpDX.DirectInput.Key.O ? Direction.ClampOn : Direction.ClampOff; //clampCalculator.OnClampPressed(dir); Debug.WriteLine(dir.ToString()); continue; } if (InputDeviceInfo.isJoysMoving) { continue; } InputDeviceInfo.isKeyBoardMoving = curKeyboardState.PressedKeys.Count() > 0 && IsControlKey(curPressedKey); if (InputDeviceInfo.isKeyBoardMoving) { //InputDeviceInfo.isKeyBoardMoving = true; switch (curKeyboardState.PressedKeys[0]) { case SharpDX.DirectInput.Key.W: positionCalculator.OnDirectionPressed(Direction.Up); break; case SharpDX.DirectInput.Key.A: positionCalculator.OnDirectionPressed(Direction.Left); break; case SharpDX.DirectInput.Key.S: positionCalculator.OnDirectionPressed(Direction.Down); break; case SharpDX.DirectInput.Key.D: positionCalculator.OnDirectionPressed(Direction.Right); break; case SharpDX.DirectInput.Key.I: positionCalculator.OnDirectionPressed(Direction.ZUp); break; case SharpDX.DirectInput.Key.K: positionCalculator.OnDirectionPressed(Direction.ZDown); break; case SharpDX.DirectInput.Key.J: positionCalculator.OnDirectionPressed(Direction.RotateLeft); break; case SharpDX.DirectInput.Key.L: positionCalculator.OnDirectionPressed(Direction.RotateRight); break; default: break; } } else { positionCalculator.Stop(); } } }
/// <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(); }
public void ThreadStart() { byte[] keybdState = new byte[256]; GetKeyboardState(keybdState); NumLock = (keybdState[(int)VK.VK_NUMLOCK] & 1) != 0; CapsLock = (keybdState[(int)VK.VK_CAPITAL] & 1) != 0; ScrollLock = (keybdState[(int)VK.VK_SCROLL] & 1) != 0; Shift = (keybdState[(int)VK.VK_SHIFT] & 0x80) != 0; LShift = (keybdState[(int)VK.VK_LSHIFT] & 0x80) != 0; RShift = (keybdState[(int)VK.VK_RSHIFT] & 0x80) != 0; Ctrl = (keybdState[(int)VK.VK_CONTROL] & 0x80) != 0; LCtrl = (keybdState[(int)VK.VK_LCONTROL] & 0x80) != 0; RCtrl = (keybdState[(int)VK.VK_RCONTROL] & 0x80) != 0; Alt = (keybdState[(int)VK.VK_MENU] & 0x80) != 0; LAlt = (keybdState[(int)VK.VK_LMENU] & 0x80) != 0; RAlt = (keybdState[(int)VK.VK_RMENU] & 0x80) != 0; var directInput = new SharpDX.DirectInput.DirectInput(); var keybdGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceType.Keyboard, DeviceEnumerationFlags.AllDevices)) { keybdGuid = deviceInstance.InstanceGuid; } if (keybdGuid == Guid.Empty) { Environment.Exit(1); } var keybd = new SharpDX.DirectInput.Keyboard(directInput); keybd.Properties.BufferSize = 128; keybd.Acquire(); string keys = ""; VK vk = 0x00; KeyboardUpdate Scan = new KeyboardUpdate(); Stopwatch holdInSW = new Stopwatch(); Stopwatch holdInIntervalSW = new Stopwatch(); holdInSW.Start(); holdInIntervalSW.Start(); var dwThread = Native.WinAPI.GetCurrentThreadId(); while (true) { Thread.Sleep(1); Native.DesktopSwitch.PollAutoDesktopThreadSwitch(dwThread); keybd.Poll(); var datas = keybd.GetBufferedData(); if (datas.Length != 0) { holdInSW.Restart(); } else if (holdInSW.Elapsed > PressedInHoldTime && Scan.IsPressed) { if (holdInIntervalSW.Elapsed > PressedInInterval) { HandleKey(keys, vk, Scan.Key, Scan.IsPressed); holdInIntervalSW.Restart(); } } foreach (var state in datas) { /*if (state.Key == Key.F12) { * Hooks.RemoveHooks(); * Environment.Exit(0); * Debug.Assert(false); * var a = (1 + 9) - 10; * Debug.WriteLine((15 / a)); * return; * }*/ if (state.IsPressed) { switch (state.Key) { case Key.Capital: CapsLock = !CapsLock; break; case Key.NumberLock: NumLock = !NumLock; break; case Key.ScrollLock: ScrollLock = !ScrollLock; break; } } switch (state.Key) { case Key.RightShift: RShift = state.IsPressed; break; case Key.LeftShift: LShift = state.IsPressed; break; case Key.LeftControl: LCtrl = state.IsPressed; break; case Key.RightControl: RCtrl = state.IsPressed; break; case Key.LeftAlt: LAlt = state.IsPressed; break; case Key.RightAlt: RAlt = state.IsPressed; break; } Shift = LShift || RShift; Ctrl = LCtrl || RCtrl; Alt = LAlt || RAlt; byte[] keyState = new byte[256]; if (CapsLock) { keyState[(int)VK.VK_CAPITAL] = 0x01; } if (NumLock) { keyState[(int)VK.VK_NUMLOCK] = 0x01; } if (ScrollLock) { keyState[(int)VK.VK_SCROLL] = 0x01; } if (Shift) { keyState[(int)VK.VK_SHIFT] = 0x80; } if (Ctrl) { keyState[(int)VK.VK_CONTROL] = 0x80; } if (Alt) { keyState[(int)VK.VK_MENU] = 0x80; } keys = ScancodeToUnicode(state.Key, keyState); vk = ScancodeToVKCode(state.Key); Scan = state; HandleKey(keys, vk, Scan.Key, Scan.IsPressed); } } }