停止 SlimDX 原始输入键盘“颤抖”
当您在文本编辑器中按住某个键时,该字符将会出现,然后您会在字符流出现之前短暂停顿。这是系统补偿某些人按住按键的时间比其他人长/暂停思考等。
我的问题是,当我在 SlimDX Direct3D11 应用程序中按住移动键时,就会发生这种情况。它不是移动相机,而是移动 1 个单位,暂停,然后流畅地移动。
我使用以下代码来捕获键盘数据:
private void InitializeKeyboard()
{
INPUT.Device.RegisterDevice(SlimDX.Multimedia.UsagePage.Generic, SlimDX.Multimedia.UsageId.Keyboard, INPUT.DeviceFlags.None);
INPUT.Device.KeyboardInput += new EventHandler<KeyboardInputEventArgs>(KeyboardInput);
}
void KeyboardInput(object sender, KeyboardInputEventArgs e)
{
if (e.Key == Keys.W) camera.MoveForward(0.3f);
if (e.Key == Keys.S) camera.MoveForward(-0.3f);
}
我使用类似的系统来捕获鼠标,并且鼠标移动工作平稳且响应灵敏,因此问题一定出在键盘为防止双击而进行的自动校正中。有人知道如何阻止硬件这样做吗?或者,如果您应该在 DirectX 11 中以不同的方式捕获输入?
When you hold down a key in a text editor, the character will appear, then you get a brief pause before a stream of characters appear. This is the system compensating for some people holding a key down longer than others / pausing in thought, etc.
My problem is that this is happening when I hold down a movement key in my SlimDX Direct3D11 application. Instead of moving the camera it moves 1 unit, pauses, and then moves fluidly.
I use the following code to capture keyboard data:
private void InitializeKeyboard()
{
INPUT.Device.RegisterDevice(SlimDX.Multimedia.UsagePage.Generic, SlimDX.Multimedia.UsageId.Keyboard, INPUT.DeviceFlags.None);
INPUT.Device.KeyboardInput += new EventHandler<KeyboardInputEventArgs>(KeyboardInput);
}
void KeyboardInput(object sender, KeyboardInputEventArgs e)
{
if (e.Key == Keys.W) camera.MoveForward(0.3f);
if (e.Key == Keys.S) camera.MoveForward(-0.3f);
}
I use a similar system for capturing the mouse, and mouse movement works smoothly and responsively, so the problem must be in this automatic correction the keyboard is doing to prevent double taps. Does anybody know how to stop the hardware from doing that? Or if you're supposed to trap input differently in DirectX 11?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是设计使然,您有 SystemInformation.KeyboardDelay 和 KeyboardSpeed。延迟是等待按键开始重复的 250 毫秒数。它通常比速度(重复按键之间的延迟)长。
仅使用 keydown 和 keyup 消息。从计时器或游戏循环的自然方式中获取重复。这还支持按下多个键,而这在您当前的方法中不起作用。
This is by design, you have SystemInformation.KeyboardDelay and KeyboardSpeed. The delay is the number of 250 msec that it will wait for the key starts repeating. It is normally longer than the speed, the delay between repeated key strokes.
Only use the keydown and keyup message. Get repetition from a timer or the natural way in which your game loop works. This also supports having multiple keys pressed, something else that doesn't work in your current approach.