Input via callbacks or functions

This is a discussion on Input via callbacks or functions within the Game Programming forums, part of the General Programming Boards category; G'day,
I've been trying my luck with a bit of simple game development. One thing that has got me stumpted ...

Input via callbacks or functions

G'day,

I've been trying my luck with a bit of simple game development. One thing that has got me stumpted is whether to use callbacks for input, or poll the input and store the values in a table which various functions check.

Basically, my table is an array of:

Code:

struct keyRow_s
{
int status; /* if the key is down */
double lastQuery; /* last time checked for hit */
};

Then using, pretty much a hash table to lookup the key in the array. Basically, when the user pushes a key should I send the key to either say, the game or a text-edit field based on the state. Or have the game and text-edit 'modules' check for input themselves?

I'm asking because I haven't really seen the method above in other projects (they all seem to use callbacks) -- and I was wondering if it was a wise idea. ie, "tell me when there's input" OR "I'll find out for myself when there's input"?

FYI, I store the last time it was checked so I can control various things like 'sticky keys'.

The problem with using polls is that you might miss some events. So you have to poll at least as often as you would get events if you used an event-driven system. Additionally, input devices are usually implemented on the hardware level with interrupts, not polls, so it wouldn't really make sense to use polls on the application side.

Any overhead you have from extra polls would be time that could be scheduled for something else.

Polling is actually what you want to do in a game setting. Buffered input works well for applications but not very well for games. During your update you just poll the keyboard and devices to find out the new inputs and respond accordingly. Given that your game normally runs 60 to 100 FPS I'm sure you won't miss any device states.