简体   繁体   English

键盘多久轮询一次Form.KeyDown事件?

[英]How often is the keyboard polled for the Form.KeyDown event?

I'm running a program at 45 frames per second. 我正在以每秒45帧的速度运行程序。 It's a game, so timely user input is important. 这是一个游戏,因此及时的用户输入很重要。 It would seem that the keydown event sometimes performs... slowly? 似乎keydown事件有时会执行...缓慢吗? As if the polling interval varies by sometimes up to 3 or 4 seconds. 好像轮询间隔有时最多间隔3或4秒。 I'm absolutely sure that the actual game isn't lagging, but rather the input is. 我绝对确定实际的游戏不会落后,但是投入是。 I plan on moving to GetKeyState(), but I'd still like to know the actual polling frequency for the KeyDown event. 我计划移至GetKeyState(),但我仍想知道KeyDown事件的实际轮询频率。

EDIT: Thought I'd post a link to the workaround I'm using here . 编辑:以为我会发布指向我在这里使用的解决方法的链接。

There is no polling frequency -- Windows uses a messaging system to deliver keypresses (and other event notifications) to applications. 没有轮询频率-Windows使用消息传递系统将按键(和其他事件通知)传递给应用程序。

The physical keypress triggers an interrupt which makes its way into the OS, which eventually sends a message to your program. 物理按键触发了一个中断,该中断进入操作系统,并最终向您的程序发送一条消息。

The lag you're seeing might be because of the event-queue being a shared service in Windows (ie Windows is sending the message a little after it occurred when there's a load on the system). 您看到的滞后可能是由于事件队列是Windows中的共享服务(即,当系统负载很大时,Windows在消息发送后不久发送了消息)。 3-4 seconds is a lot of lag, though -- I'm not sure what could be causing it. 但是,3-4秒是一个很大的滞后-我不确定是什么原因造成的。

See this article for more information. 有关更多信息,请参见本文

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM