Input Manager

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Input Manager

Post by Karai17 »

Input Manager (I need a better name for this!) is licensed under the MIT license. Basically, do what ever you want with it as long as you leave the license info in the lua file. c:

Input Manager supports the following input:
  • Keyboard
  • [list]
  • keypressed()
  • keyreleased()
  • isDown()
[*]Mouse[/*]
  • mousepressed()
  • mousereleased()
  • isDown()
[*]Joystick[/*]
  • joystickpressed()
  • joystickreleased()
  • isDown()
  • getAxis()
  • getHat()
[/list]

I was inspired to write this library after reading this website: http://tannerrogalsky.com/blog/2012/04/ ... in-love2d/

Please report any bugs, feature requests or comment on general usefulness/structure/whatever. c:

Quick documentation:

Code: Select all

--[[
	Add Button Binding
	
	device		- Hardware device
	toggle		- Callback
	button		- Button code
	action		- Function to execute
	joystick	- [optional] joystick number
]]--
Input:addButton(device, toggle, button, action, joystick)

--[[
	Add Hat Binding
	
	joystick	- Joystick number
	hat			- Hat number
	button		- Button code
	action		- Function to execute
]]--
Input:addHat(joystick, hat, button, action)

--[[
	Add Axis Binding
	
	joystick	- Joystick number
	axis		- Axis number
	action		- Function to execute
]]--
Input:addAxis(joystick, axis, action)

--[[
	Remove Button Binding
	
	device		- Hardware device
	toggle		- Callback
	button		- Button code
	joystick	- [optional] joystick number
]]--
Input:removeButton(device, toggle, button, joystick)

--[[
	Remove Hat Binding
	
	joystick	- Joystick number
	hat			- Hat number
	button		- Button code
]]--
Input:removeHat(joystick, hat, button)

--[[
	Add Axis Binding
	
	joystick	- Joystick number
	axis		- Axis number
]]--
Input:removeAxis(joystick, axis)

--[[
	Key Pressed Callback
	
	key			- Key code
	unicode		- Key unicode
]]--
Input:keypressed(key, unicode)

--[[
	Key Released Callback
	
	key			- Key code
	unicode		- Key unicode
]]--
Input:keyreleased(key, unicode)

--[[
	Mouse Button Pressed Callback
	
	x			- X position of cursor
	y			- Y position of cursor
	button		- Button code
]]--
Input:mousepressed(x, y, button)

--[[
	Mouse Button Released Callback
	
	x			- X position of cursor
	y			- Y position of cursor
	button		- Button code
]]--
Input:mousereleased(x, y, button)

--[[
	Joystick Pressed Callback
	
	joystick	- Joystick number
	button		- Button code
]]--
Input:joystickpressed(joystick, button)

--[[
	Joystick Released Callback
	
	joystick	- Joystick number
	button		- Button code
]]--
Input:joystickreleased(joystick, button)

--[[
	Key Held Down
	
	dt			- Delta time
]]--
Input:keyboardisdown(dt)

--[[
	Mouse Button Held Down
	
	dt			- Delta time
]]--
Input:mouseisdown(dt)

--[[
	Joystick Button/hat/Axis Held Down
	
	dt			- Delta time
]]--
Input:joystickisdown(dt)

--[[
	Update All Devices
	
	dt			- Delta time
]]--
Input:update(dt)
You can download the library here: https://github.com/karai17/love2d-input-manager
Last edited by Karai17 on Mon Oct 08, 2012 9:57 pm, edited 5 times in total.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: Input Manager

Post by qaisjp »

What can it be used for?
Lua is not an acronym.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Input Manager

Post by Karai17 »

I made this to try to make managing input a bit easier and cleaner. A one-stop-shop for all three input devices. You just need to bind a key or button or hat or axis to some function and every time you interact with it, it'll fire it off.

The joystick management, in my opinion, is the most interesting bit of it.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: Input Manager

Post by qaisjp »

Karai17 wrote:I made this to try to make managing input a bit easier and cleaner. A one-stop-shop for all three input devices. You just need to bind a key or button or hat or axis to some function and every time you interact with it, it'll fire it off.

The joystick management, in my opinion, is the most interesting bit of it.
Ahah, so just a Bindmanager
Lua is not an acronym.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Input Manager

Post by Karai17 »

Pretty much, yeah. It's not revolutionary by any means, but I'm hoping it's designed well enough that it can make things a bit easier on my fellow lovers. c:
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: Input Manager

Post by qaisjp »

Karai17 wrote:Pretty much, yeah. It's not revolutionary by any means, but I'm hoping it's designed well enough that it can make things a bit easier on my fellow lovers. c:
Yeah, it's nothing new, just another way of doing what's already done.
Lua is not an acronym.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Input Manager

Post by Karai17 »

Shameless bump. Not much real discussion happened when I posted this four months ago so mayhaps people will notice it now and give it some actual critique. I can write up some documentation if that would help folks use this. the main.lua in the repo is simple test program that allows you to use your keyboard, mouse and gamepad to control the little box on screen. It also shows you how to add this to your own project if you deem it worthy.

Feature requests are welcome, too, if this is missing something you'd like to see.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Input Manager

Post by Inny »

You can probably lose the dependency on the HUMP library by making the Input table a singleton, rather than a class (assuming no other feature of HUMP that you may be using that I missed when looking at the code). The way you'd do this is by changing the class contuctor to just Input:init and call it from love.load.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Input Manager

Post by bartbes »

This is of course the perfect time to plug my own initiatives, in this case Class Commons.
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Input Manager

Post by Inny »

bartbes wrote:This is of course the perfect time to plug my own initiatives, in this case Class Commons.
And it's a great initiative. I was just operating on the premise that with any game, you'd probably only have one object at a time acting as the adaptor between the game and love.keyboard, love.mouse, and love.joystick, so why complicate the world with a class library when a straight table would do the trick?
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests