I'm currently focused on addressing the X-axis aspect of the left thumbstick emulation for an Xbox controller using a keyboard. I've come across a GitHub project that offers the capability to mimic an Xbox controller's functionality and translate keyboard key presses into corresponding Xbox controller inputs. This project also includes an option for controlling the analog stick. However, I've noticed that the analog stick in this project only recognizes two distinct values for the X-axis: one for turning left and another for turning right.
To enhance this emulation and introduce more granular control, I've been exploring the possibility of incorporating intermediate values between the extreme left and right positions of the analog stick. My idea involves leveraging the 'rate of keypress on the keyboard' to determine these in-between values. For instance, if I designate the left and right arrow keys on the keyboard to control the X-axis, I envision implementing a stopwatch mechanism to measure the time interval between consecutive keypresses.
The concept is as follows: if the time interval is approximately 100 milliseconds, this could correspond to a more extreme X-axis tilt value (e.g., a 'short' value of 30,000). Similarly, a time interval of around 200 milliseconds might translate to a value of 27,000, and so on. In cases where no keypress is detected, the X-axis value should gradually return to zero over time.
While utilizing a stopwatch for timing is an option, I've also observed that the GitHub project I'm working with checks for keypresses at regular intervals. In its current state, every time I press the button designated for controlling the X-axis, the analog stick's X-value is instantly set to the maximum. Upon releasing the button, the X-value promptly returns to zero.
Conceptually, I'm confident in devising the algorithm for adjusting the X-axis value based on the keypress rate. However, I'm encountering difficulties when attempting to implement this algorithm within the existing C# codebase of the Keyboard Splitter GitHub project.
If you have any insights or suggestions regarding how to seamlessly integrate this algorithm into the project's C# codebase, I would greatly appreciate your assistance.
here is the github project:keyboard splitter
private string SetAxis(IVirtualGamepad gamepad, Mapping mapping, bool isKeyDown, bool hasOppositeDown)
{
uint axis = (uint)mapping.Function;
short axisValue = (short)(mapping.TargetValue);
short oldValue = gamepad.GetAxisState(axis);
short newValue = isKeyDown ? axisValue : (short)XboxAxisPosition.Center;
if (hasOppositeDown && !isKeyDown)
{
if ((short)mapping.TargetValue == (short)XboxAxisPosition.Min)
{
newValue = (short)XboxAxisPosition.Center;
}
else
{
newValue = (short)XboxAxisPosition.Center;
}
}
if (oldValue == newValue)
{
return null;
}
gamepad.SetAxisState(axis, newValue);
return ((XinputAxis)axis) + " Axis " + ((XboxAxisPosition)newValue);
}
The above code is the implementation done by the Keyboardsplitter Author.
gamepad.SetAxisstate(axis, newValue) controls x-axis directly. the above method is called everytime the kkey is pressed. i need to fine a way to remember few variables when the method is called again.
can you guide me on how to integrate this idea into code?