Adam's Lair Forum

[Plugin] Input Mapping
Page 1 of 3

Author:  loeller [ 2016/06/14, 21:06 ]
Post subject:  [Plugin] Input Mapping

(edit - 2017.04.01.: this description is outdated, but I choose to keep it for historical purposes. The current status of the project and instructions can be found in the fresh posts in this topic, and on GitHub.)

This weekend's project was something for Duality, a keyboard mapping / input manager plugin. It's a feature that most engines out there have, definitely useful, and relatively straightforward, and last, but not least I had good time working on it, so if you don't really have any free-time activity nowdays, Duality plugin development is something I'd recommend :]

Under 'View' menu, there's a new entry called 'Input Mapping'. It spawns a new editor window, which can be snapped, docked and positioned like any other. In that menu, you need to add and name the so called Virtual Buttons, then assign physical keys to them. Do this by selecting the key's name in the drop down list next to the green plus icon, then clicking the icon. The assigned keys can be removed by clicking the red minus icon, or they can be modified just by The plugin saves these changes automatically to the 'keyMapping.res' resource file, which you need to ship with the project.


If the Virtual Buttons are created, you can refer to them in the code by their name. Notice, that first you need to add the assembly to the Visual Studio project as a reference.

using MFEP.Duality.Plugins.InputPlugin;

Vector2 direction = Vector2.Zero;
if (InputManager.IsButtonPressed("Right")) //Right is the Virtual Button's name
    direction += Vector2.UnitX;

There are also IsButtonHit and IsButtonReleased methods available.

Known Issues
  • At the moment, the user can assing new VirtualButtons to the InputManager via code. These changes do not reflect in the editor window. The user might need to do this (in game keybinding management for example), so it'd be nice to implement this.
  • FIXED Multiple instances of the single key cannot be added to the same Virtual Button, but if the user changes an existing key, the program allows the same key. This leads to weird behaviour, thus needs to be fixed.

What's next
The plugin is not tested extensively, I'd be grateful if I got any help on this. The above mentioned bugs need to be fixed, and a package should be released (although I don't really know how that stuff works)
As always, input (and some testing) is most appreciated! :]


Author:  Adam [ 2016/06/14, 22:51 ]
Post subject:  Re: [Plugin] Input Mapping

Nice ^^ Something like this is indeed missing in Duality. As soon as you're ready for a stable release, make sure to add your plugin to the list of community projects!

Gave it a short test, added numpad key controls and all seems to be working as expected. Are you planning to add support for mapping input across Gamepad / Joystick / Mouse as well?

Quickly glanced over some code and found that you're essentially using a dummy resource to load and save your settings. You don't actually need to do this though :) If you just quickly want to save or load some data that is not part of the content system, you can do this:

Foo obj = ...;
Serializer.WriteObject(obj, "", typeof(XmlSerializer));
Foo obj = Serializer.TryReadObject<Foo>("");

Congratulations to your first Duality plugin btw!

Author:  loeller [ 2016/06/15, 18:47 ]
Post subject:  Re: [Plugin] Input Mapping

Thanks for the feedback!
Adam wrote:
Are you planning to add support for mapping input across Gamepad / Joystick / Mouse as well?

Yeah, I've been thinking about this stuff, and I don't want to implement gamepad support just for the digital gamepad buttons. Instead, a proper handling for analogue controls would be necessary, which is not in the scope until the current system is cleaned up.
Although including the mouse buttons is a good - if not a neccessary step. Just forgot about them... :redface:
Thank you for the code snippet too :]

Author:  loeller [ 2016/06/17, 10:42 ]
Post subject:  Re: [Plugin] Input Mapping

Fixed some bugs, and marked the button-adding interface internal until proper communication is built between the ui and the core plugin.
Also uploaded the nuget packages. They can be downloaded in the Duality package manager, but it does not copy the .dll-s to the Plugins folder, although I tagged the packages accordingly (Duality Core/Editor Plugin ...). Can someone point me what I'm doing wrong?
Thanks in advance :]

Author:  Adam [ 2016/06/17, 10:58 ]
Post subject:  Re: [Plugin] Input Mapping

I've downloaded the package and extracted it to have a look at the nuspec file, since I couldn't find it in your github repo. Not sure if it has been altered by the building process, but apparently there are no files defined in it?

<?xml version="1.0"?>
<package xmlns="">
    <title>InputPlugin (Core)</title>
    <authors>Lőrinc Serfőző</authors>
    <owners>Lőrinc Serfőző</owners>
    <description>Keyboard abstraction plugin for Duality game engine.</description>
    <summary>Keyboard abstraction plugin for Duality game engine.</summary>
    <releaseNotes>Initial release.</releaseNotes>
    <copyright>Copyright 2016</copyright>
    <tags>Duality Core Plugin Keyboard Input Manager Abstraction</tags>
      <dependency id="AdamsLair.Duality" version="2.0.0" />

To get an idea on how to define the files for a package, take a look at some of the official nuspecs, this one for example.

If you did define the file correctly, which I'd assume because the dll is actually in the lib folder, then I'm not entirely sure what's wrong. Can you share your original nuspec files?

Edit: Okay, so I debugged this with my local source version of Duality an when investigating your packages, they do have the Duality tag, along with Keyboard, Input, etc., but they do not have the Plugin tag. This makes the package manager think it's a non-plugin binary and so it ends up in the main directory. In the nuspec I retrieved, there does seem to be a Plugin tag... same for the NuGet gallery entry. But when asking the NuGet library at runtime, it's just not there. "Core" is missing too, but that's not actually vital.

Author:  loeller [ 2016/06/17, 11:42 ]
Post subject:  Re: [Plugin] Input Mapping

Hmm, the original .nuspec files are in the CorePlugin and EditorPlugin folders on github, but these are different from the embedded ones, since I modified them using's online editor (adding tags, etc). I suppose this is the problem, so now will edit the original .nuspec files, create the packages with them, push to and see what happens

Edit: The weird thing is, that even though the .nuspec contains the <files> element, after processing it using the command nuget pack InputPlugin.core.nuspec, the created .nupkg does not contain them.

Edit of edit: The former stuff is true for the other Duality .nupkg-s so I guess it's normal, and not a failure.

Author:  loeller [ 2016/06/17, 12:02 ]
Post subject:  Re: [Plugin] Input Mapping

Now it seems to be working. Thanks for the quick help :]

Author:  Adam [ 2016/06/17, 12:13 ]
Post subject:  Re: [Plugin] Input Mapping

Great! And good thinking with the online editor as potential cause for the tags problem. I was about to take a deep-dive into the NuGet.Core source code and trust me, I'm very glad your quick solution spared me of that :D

Author:  Cross [ 2016/06/24, 09:36 ]
Post subject:  Re: [Plugin] Input Mapping

Wow! Great job! :)

Author:  loeller [ 2016/06/24, 11:49 ]
Post subject:  Re: [Plugin] Input Mapping

Cross wrote:
Wow! Great job! :)

Thank you! :]

Page 1 of 3 All times are UTC + 1 hour [ DST ]
Powered by phpBB® Forum Software © phpBB Group