Input polling

More often than I’d like (never) my input polling misses a key/mouse press. Now by this I don’t mean the mouse/keyboard listener events. I mean my Input/Keyboard/Mouse classes.

I have it setup so that when mousePressed() gets called I call my own function in Mouse sending a buttoncode over and store the result (true) in an array for that button (same idea for the keyboard). Every frame/update I call Input.update(). This takes the current key presses and puts them in another array “last_key_presses”. last_key_presses is the array I read from every frame to tell if a button/key was pressed.

I think the problem lies with the fact that a mouse press fires an event (on another thread) that gets wiped out when I call Input.update() on the main thread, but I’m not sure how to fix it.

Any ideas?

What library are you using?

If you don’t want to miss events, don’t use flags.
Store the input events in a queue and process them in your game loop.

@CopyableCougar4 I’m using my own implementation. I feel like I’m an engine builder and I’m just doing it for fun so I’d rather not use a library.

@Abuse Hmmm…yeah I was reading up last night on it and was hoping to avoid this, but maybe I can’t.

Is it a common occurrence for polling to miss events? Mine currently misses almost every other one.