class based key mapper with joystick/gamepad support

im releasing a bit of my codebase that i think will be useful. it still has some stuff to be done, but hopefully it will make someones life easier.

here is my keymap setup which has support for gamepads and joysticks too. i plan to add the globalDict part and a method to change the key binds.

the goal is simplicity and flexibility. no complex blend setups or a pile of game properties to keep track of.


-to download, click the “source code (ZIP)” link
–copy the scripts from PY into your scripts folder or add them to your blend (make internal)
–edit line 28 in keymap.py:
—[import PY.input as input] replace PY with your folder
—[import input] if your scripts are internal/packed

never done this whole github thing before, so let me know if im doing it wrong :smiley:

1 Like

Check this: http://coredoc.royalwebhosting.net/api/event.html#key-bindings

Official Release 0.1.0 is out!

Featuring:

  • Stability fixes and cleanups
    -A few more steps toward pep8
    -Initial API

Added some documentation, still WIP. Feature requests and feedback are welcome.

Or if you still have no idea what its supposed to do, ill get a sample blend up soon.

what i have here isnt an addon and its not for upbge.

What I posted is just an API, which happens to be implemented with Python using the BGE API just as yours, and it’s trivial to port to BGE or implement from scratch on any other engine.

In fact, it’s the design that counts rather than its implementation, and it’s at that that linked rather than the code or the full addon.

Added a gamepad/joystick axis and button ID finder. Look in the Extras folder.

New Beta release is out featuring simpler config and other speed and efficiency updates. Unfortunately old keymaps will not be compatible.

is it complete?
and how do I install it from the above link?^ I dont really know github well

its complete. im just making sure im not over looking something. the beta version is as good as a release. let me know if you find something wrong.

all you need to do is copy keymap.py and input.py into the folder where you put scripts. if that folder is PY, then it should work as is.

if not, then you need to modify line 28 in keymap.py, replace “PY” with your folder. this is also where you define all your own key binds.

if the scripts are in the same folder as the blend OR packed/internal:

import input

let me know if this isnt clear enough.

Version 0.2.0 is Finally here!

Featuring:

  • More Efficient Keybind Class Arguments
  • Multiple Bind Dictionaries Supported for grouping or hardcoding keys
  • A Sample Blend
  • Scene Switching Stability Improvements
  • Speed Improvements
  • Bug Fixes and some more PEP Compliance

NOTE: old keybinds wont be compatible with this release.

nice code and easy to understand but the mouselook class is a bit out of place in there, should that not be placed in its own file.

I create a screen with game commands and ‘press any key’ after you activate it,

then when you press the button it saves the rule in a dictionary then it looks that up later when proccessing the input and spits out the gamecommand to the target agent

control = {eventString:[‘GameCommand’,index, playerTargetSlot] }

I take each of these and build a game command list per agent, and aort by index and then copy strings to a list if they are not in it, stripping doubles and serializing the list…

(the order will always be the same)

should work for more than 1 player as well*

@BPR:

i have an idea how to save keys. i just need the time to put it in place. in fact some of the changes i made were ground work.

logic.globalDict = {“Profiles”: {“Name”: {“Keys”: {“BIND”: “AKEY”}} etc}, “ActProf”: “Name”}

i could make a prefix to “BIND” to indicate which bind dictionary its stored in. like “BINDS.JUMP” or “SYS.PAUSE”. but the whole point of different dictionaries is to prevent some keys from being remapped.

if you wanted, you could make a branch with proposed code.

glad to hear it was easy to follow, that was a main goal.

for the sake of simplicity, all core classes and functions will be put in the input.py. otherwise it would mean more importing and trying to figure out what classes are where when building a keymap. plus, less files means easier to maintain and install.

thanks for the feedback!

im looking into starting a branch optimized for UPBGE. if someone is interested in helping out, that would be great. that someone would have alot of freedom to make changes in that branch.

also, in the near future im going to create a binds manager example blend so you can interact with the keybinds in game. you could even drop it next to your game and use the “start game from file” to easily snap it to your project.

Are you able to share the exact specifications of your project ?
If its about implementing your mapper class into the bge, I would not recommend it as I don’t think its general enough. Maybe make it an official side Python module ?
What is your goal ?

the goal is to make a setup thats easy to snap on to a project. nothing deep. i want it to make it simpler for newbies to get into python, while also providing something scalable to fit any project. less of an example and more like an asset. copy the files, import keymap, done.

ive even considered how to make it work with the keyboard sensor brick for those who like them. not likely to happen due to the complexity of the solution on the users end.

getting joysticks and gamepads to work in harmony with keyboard commands is the strongest point so far i think. not to mention JUST_ACTIVATED for gamepad buttons.

im new to this whole open source development stuff, so im open to suggestions, questions, and critics. not sure if the project is as simple to use as i think it is. with little in the way of feedback, its hard to advance with confidence.

work on the keymapping utility is moving forward. i have the visual elements all in place. some efficiency issues still need to be worked out on the code side of things.


Looks super cool !

Are these all GameObjects or did you use an UI system ? (bgui / compz / twisterUI / …)

(also what does S / C / A stands for ?)

its all game objects, it makes it easy to edit and create your own, or append it in. i have one item setup and just add it per number of keys.

shift, ctrl, alt: true is blue, red is false, gray is none. i plan on having a little text object to say what things are when your is mouse on them.

thanks!