I can show you exactly what I'm doing:
https://github.com/vincentgires/lovegam ... einput.lua
This is a small wrapper around inputs coming from mouse, keybord or joysticks.
For the moment, we can set "actions" with
Code: Select all
input = Input:new()
input:bind_action('left', {device='keybord', value='space'})
input:bind_action('left', {device='joystick', number=1, event='hat', index=1, value='l'})
And use it in in game with
Code: Select all
if input:is_active('left') then
-- is down
end
if input:is_pressed('left') then
-- is pressed
end
if input:is_released('left') then
-- is released
end
For the moment, the only callback that is needed is the love.update(). I don't use any pressed/released callback of love to have it very easy to deploy and use in multiple projects and I compute it in the module.
Something else I'd like to do is the listen() function I start to implement to listen which key/button/hat/axis is pressed in the context of setting the key from a menu or something like that. Right now, I did all the events of joysticks scanning all the buttons, axis, etc. Is that so bad? It doesn't seem too heavy, and even if it is, this is only for key configuration, so I'm not sure that is so wrong. What do you think? The only thing I didn't do yet is the keyboard. That's why I start this thread, because I didn't found a way to scan all keys inside the update/listen function without using love callbacks. But if you tell me that's a very bad idea, I should maybe not do it that way.
Other library exists like
that one which seems good but look inside the main.lua: this is something I did want to avoid: all the callbacks are "sent" to the module file which makes the library not as convenient to use instead of just not having to do that.