univrsal / input-overlay

Show keyboard, gamepad and mouse input on stream
GNU General Public License v2.0
3.03k stars 249 forks source link

[Basic feature request] Render presses for a longer time #425

Open jkidd1 opened 3 weeks ago

jkidd1 commented 3 weeks ago

Thank you very much for creating and maintaining this very useful plugin. In my case, I am using it to visualize hits on a drum controller (each hit maps to a keyboard press). The issue is that the keys/hits only stay pressed for a very short amount of time, so the visuals ultimately do not look very smooth. I am wondering whether it would be easy/trivial to add an option for extending the render of the "pressed" icon. For example, the key could display the "pressed" state for an additional second after it is released.

If this is too much effort to implement, I totally understand. And if it's not done through the plugin, does anyone have tips for how it could be accomplished in OBS? Is there perhaps another plugin I could use in tandem with this one?

univrsal commented 3 weeks ago

You could use the browser source. https://github.com/univrsal/input-overlay/tree/master/data/overlay_render contains an example for rendering the gamepad preset in the browser source. It cold be adapted to load any other gamepad preset and to extend button presses.

jkidd1 commented 3 weeks ago

Thank you so much for the suggestion. I have coding experience but am not familiar with javascript, so my apologies if I am a bit slow. I found a draw function in here in elements.js. If I understand correctly, this is where you perform the trick of shifting the render window downwards in the texture file so that the "pressed" image is shown. The shift only happens if this.pressed is true. I also see that you have some wrappers, e.g., on_keyboard_input, that presumably keep track of the state of each key code on each tick. What approach should I be taking to the modification? Should I be trying to keep this.pressed true for additional ticks after the initial change of the state? Any advice would be highly appreciated.

univrsal commented 2 weeks ago

Yeah basically just keep track of whether the button was pressed before and if it isn't any more delay the switch from true to false by however long you wan the presses to last.