[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to handle keyboard inputy
> Hey all.
>
> Doing a game with OpenGL, using glutKeyboardFunc to get some
> keypresses. However, this is not good:
>
> a) Having to handle both KeyboardFunc and SpecialFunc, and *Up* funcs is
> tiresome, and I have no garantee that a keydown will eventually
> generate a key up.
> b) I can't handle multiple pressed keys.
>
> I know absolutly nothing about coding in X. So, what is the preferred way
> to handle keyboard/mouse/joystick input?
>
> I have an idea that somehow these events should be handled by the same
> logic, ie, I have one "stream" of events. Maybe I need to sample the mouse
> and joystick regulary, but I don't mind.
>
> Suggestions appreciated.
>
I do it like this:
KeyboardFunc and SpecialFunc and so on read the in they store it in a
character buffer if it's a typeable character and it's a "down" event
and also in a keymap, so they keymap has the state of all the
buttons. I put all the mouse buttons and stuff in there as
well. Likewise the state holds the mouse positions and a little state
machine that knows what the mouse is doing ( moving, dragging,
clicking etc).
During the "idle" event I just read the state out. It means that the
idle one is the only one with any real processing happening in it, and
when it's called it's got a nice consistent state view of the keyboard
and mouse.
---------------------------------------------------------------------
To unsubscribe, e-mail: linuxgames-unsubscribe@sunsite.auc.dk
For additional commands, e-mail: linuxgames-help@sunsite.auc.dk