Re: [AD] Input routines

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2008-05-02, Paul Suntsov <siegelords_abode@xxxxxxxxxx> wrote:
> Some advanced keyboard handling routines rely on checking the entire state of the keyboard to
> function, e.g. routines that assign the time each button was held down. Event based keyboard
> handling is suboptimal, since if the window loses focus, you may end up with a stuck key if the
> key's state changed during the time the window lost focus. And, I am guessing, that it is faster
> to get the entire state in one call than to iterate over all buttons using al_key_down.

That's right.  I think we ought to make al_key_down() inline as well for
efficiency in this case.

The other reason is theoretical.  I didn't want `al_key_down(A) &&
al_key_down(B)' to evaluate to true even though the user never held down
A and B simultaneously.  Of course, that has no practical difference and
depending on the implementation that can still happen, etc.

> I think that al_get_*_state functions should stay, and there should be an al_joystick_key_down of
> some sort, for consistency.

And probably we should provide a version of al_key_down() which doesn't
take a keyboard state.

> 
> --- Ryan Dickie <goalieca@xxxxxxxxxx> wrote:
> 
> > void al_get_keyboard_state(ALLEGRO_KBDSTATE* ret_state)
> > bool al_key_down(const ALLEGRO_KBDSTATE* state, int keycode)
> > bool al_set_keyboard_leds( int leds ) //notice, no keyboard or
> > keyboard state supplied
> > 
> > I have a question. What is the purpose (for the end user) for getting
> > the keyboard state to check if a key is down?
> > Wouldn't it be more straight forward for a user to call 'bool
> > al_key_down(int keycode)'
> > 
> > The same goes for mouse routines
> > void al_get_mouse_state(ALLEGRO_MSESTATE* ret_state)
> > bool al_mouse_button_down(ALLEGRO_MSESTATE* state, int button)
> > 
> > With the joysticks you can fetch the state given a joystick.. so I do
> > see a point.
> > void al_get_joystick_state(ALLEGRO_JOYSTICK* joy, ALLEGRO_JOYSTATE* ret_state)
> > but with the joystick there is no button down function etc.

The joystick state is rather more complex and so I thought the user
should just access the structure fields in this case.  We can add
functions for consistency.

Peter





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/