Skip to content

Input stuff - #4804

Open
SuuperW wants to merge 8 commits into
TASEmulators:masterfrom
SuuperW:input-stuff
Open

Input stuff#4804
SuuperW wants to merge 8 commits into
TASEmulators:masterfrom
SuuperW:input-stuff

Conversation

@SuuperW

@SuuperW SuuperW commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

This PR changes both JoypadApi.SetAnalog overloads, so that they behave similarly to the Set methods for buttons. This means (1) using OverrideAdapter instead of the sticky controller [fixes the Lua issue observed in #4766], (2) changing the way analog values are unset in the dictionary overload is by passing a dictionary without the relevant keys [allowing it to set neutral axis values], and (3) for Lua, throwing an exception if the input value cannot be converted to an int [instead of silently failing].

The documentation for the set methods are updated to include "as if the inputs came from the user". This implies that #4769 is indented behavior; auto-fire will obviously work when the button is not otherwise held. Sticky holds and autofires will also interact with buttons held by joypad.set. But this implication is probably not very obvious and better documentation may still be beneficial. Alternatively, we might want to change the behavior.

It also fixes the behavior of the set methods when called from the frame start event, adds tests, and cleans up some code a little bit.

Check if completed:

SuuperW added 8 commits July 26, 2026 13:27
- ButtonOverrideAdapter -> OverrideAdapter because it isn't just for buttons
- ClickyVirtualPadController -> ClickyController because it is not related to the Virtual Pad tool
…not need to know how to use it

fix: Soft/Hard reset menu items did not work if Lua was calling `joypad.set` from `onframestart` event.
@perfectchud

Copy link
Copy Markdown

I've tested this fix and it works perfectly. My mouse movements no longer override lua script's X/Y positions, and I don't have to manually unbind Touch X and Touch Y whenever I want to run a lua script that does touch inputs.
There is one issue that persists: my accidental left clicks still trigger unwanted inputs that would interfere with intended result of my lua script. But here's a workaround: force the script to do joypad.set({ ["Touch"] = false }) whenever the script isn't doing any Touch inputs.

}

public void SetAnalog(IReadOnlyDictionary<string, int?> controls, int? controller = null)
public void SetAnalog(IReadOnlyDictionary<string, int> controls, int? controller = null)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks like it would work with int?, so can you leave the signature as-is until next release? Better yet, have both as overloads and mark the nullable one [Obsolete].


[LuaMethodExample("joypad.setanalog( { [ \"Tilt X\" ] = -63, [ \"Tilt Y\" ] = 127 } );")]
[LuaMethod("setanalog", "Sets the given analog controls to their provided values as autoholds. Set axes to the empty string to clear individual holds.")]
[LuaMethod("setanalog", "Sets the given analog controls to their provided values for the current frame, as if the inputs came from the user. Any analog inputs previously set but missing from the given table will be unset.")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs a deprecation cycle. Might need to resort to renaming it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New method could be named set_analog since that's a good name change anyway.

{
foreach (var kvp in expected)
{
Assert.IsTrue(actual.TryGetValue(kvp.Key, out object value), $"Expected to find key {kvp.Key} but did not.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Assert.IsTrue(actual.TryGetValue(kvp.Key, out object value), $"Expected to find key {kvp.Key} but did not.");
Assert.IsTrue(actual.TryGetValue(kvp.Key, out var value), $"Expected to find key {kvp.Key} but did not.");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var is generally a bad idea, since it provides less information to the reader. Code is easier to read and understand when type names are visible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants