/// <summary> /// キーボードを使用したい場合は実行してください /// その後GetKeyBoardでKeyboardを取得してください /// </summary> public static void SetupKeyboard() { if (IsUseKeyboard) { return; } // 参考サイト // http://io-fia.blogspot.com/2011/03/slimdxdirect2d.html _dxKeyboardInput = new SlimDX.DirectInput.DirectInput(); _keyboard = new SlimDX.DirectInput.Keyboard(_dxKeyboardInput); _keyboard.SetCooperativeLevel( SlimDXSketch.Instance.Handle, SlimDX.DirectInput.CooperativeLevel.Foreground | SlimDX.DirectInput.CooperativeLevel.Nonexclusive ); _keyboard.Properties.BufferSize = 4; }
public DKeyboard(SlimDX.DirectInput.Keyboard underlyingKeyboard) { underlyingKeyboard.Acquire(); mboard = underlyingKeyboard; System.Threading.Thread mthread = new System.Threading.Thread(thetar); mthread.Start(); }
void thetar() { try { internform = new RenderForm("DirectX - SlimDX library"); Direct3D my3d = new Direct3D(); presentation = new PresentParameters(); presentation.BackBufferHeight = my3d.Adapters[0].CurrentDisplayMode.Height; presentation.BackBufferWidth = my3d.Adapters[0].CurrentDisplayMode.Width; presentation.DeviceWindowHandle = internform.Handle; presentation.Windowed = false; int adapter = 0; foreach (AdapterInformation et in my3d.Adapters) { if (et.Details.Description.ToLower().Contains("perfhud")) { adapter = et.Adapter; } } if (adapter == 0) { graphicsDevice = new Device(my3d, 0, DeviceType.Hardware, internform.Handle, CreateFlags.HardwareVertexProcessing, presentation); } else { //presentation.Windowed = true; //presentation.BackBufferHeight = internform.Height; //presentation.BackBufferWidth = internform.Width; graphicsDevice = new Device(my3d, adapter, DeviceType.Reference, internform.Handle, CreateFlags.HardwareVertexProcessing, presentation); } SlimDX.DirectInput.DirectInput input = new SlimDX.DirectInput.DirectInput(); SlimDX.DirectInput.Keyboard keyboard = new SlimDX.DirectInput.Keyboard(input); keyboard.SetCooperativeLevel(internform.Handle, SlimDX.DirectInput.CooperativeLevel.Foreground | SlimDX.DirectInput.CooperativeLevel.Exclusive); mboard = new DKeyboard(keyboard); SlimDX.DirectInput.Mouse mouse = new SlimDX.DirectInput.Mouse(input); mouse.SetCooperativeLevel(internform.Handle, SlimDX.DirectInput.CooperativeLevel.Foreground | SlimDX.DirectInput.CooperativeLevel.Nonexclusive); mmouse = new DMouse(mouse); tvent.Set(); MessagePump.Run(internform, messenger); } catch (Exception er) { inception = er; tvent.Set(); } }