Bloodyaugust
Bloodyaugust

Reputation: 2503

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

I'm running a program at 45 frames per second. It's a game, so timely user input is important. It would seem that the keydown event sometimes performs... slowly? As if the polling interval varies by sometimes up to 3 or 4 seconds. 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.

EDIT: Thought I'd post a link to the workaround I'm using here.

Upvotes: 0

Views: 634

Answers (1)

Cameron
Cameron

Reputation: 98816

There is no polling frequency -- Windows uses a messaging system to deliver keypresses (and other event notifications) to applications.

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 (i.e. Windows is sending the message a little after it occurred when there's a load on the system). 3-4 seconds is a lot of lag, though -- I'm not sure what could be causing it.

See this article for more information.

Upvotes: 5

Related Questions