Build Your Own Arcade Controls Forum

Main => Main Forum => Topic started by: mako_cc on March 08, 2024, 11:35:11 am

Title: U-HID Convert analog inputs to keypress?
Post by: mako_cc on March 08, 2024, 11:35:11 am
Hello.  First time poster.  Hoping to find some U-HID controller expertise.  Is there a way to convert analog joystick inputs to keypress outputs to the computer?  For example, outputting arrow key codes for the directional inputs from the joystick?

Hopefully this makes sense.
Thanks for the help,
Chad
Title: Re: U-HID Convert analog inputs to keypress?
Post by: PL1 on March 08, 2024, 06:30:03 pm
Is there a way to convert analog joystick inputs to keypress outputs to the computer?  For example, outputting arrow key codes for the directional inputs from the joystick?
Pretty sure you can't do that with any commercially-available encoder.

You're vaguely describing what appears to be an unusual edge-case so more details are needed to give more specific advice.

Theoretically, there are several ways to do what you describe.  DISCLAIMER: I haven't tested these approaches.

1. Hardware: Wire the potentiometers differently so the analog stick behaves like an 8-way stick.

To understand how pots normally work and are wired, read How a potentiometer provides the voltage for an analog encoder to measure (https://wiki.arcadecontrols.com/index.php/Analog_Encoders).

Instead of the three tabs being 5v, wiper, and ground (or ground, wiper, and 5v), connect tab #2 (middle) to ground and tabs # 1 and 3 to the left and right input ports. (or right and left)

As long as the pot is a high enough resistance value, when it is centered, it will keep the input ports at a logic high level.

                    Center
Left port --------|-------- Right port
                        ^
                   Ground

When you push the joystick lever left, the wiper will move closer to left input port decreasing the resistance between the left port/ground and increasing the resistance between right input port and ground.  When you push the joystick lever far enough left, the left port is pulled down to logic low which triggers the output.  The right port stays at logic high so it is not triggered.

                    Center
Left port --------|-------- Right port
                ^
            Ground

2. Software/firmware:  I can't help you much beyond the general info below.   :dunno
The software/firmware approach is much more flexible than the hardware approach, but you need to have the programming skills to make it work.
- If you're good at C++, look into adapting the code that MAME uses to convert analog control inputs to "INC" and "DEC" keypresses.

Use software like an AHK script or firmware on an Arduino (32u4 or newer with analog inputs) to monitor the current X-axis and Y-axis positions and output the desired keystrokes.

In a 10 bit A/D setup, there are 1024 possible positions on each axis so a value of 512 would be centered.

If you divide that range into 8 parts, each part will be 128 wide so a value between 228 (512-64) and 576 (512+64) on the X-axis would be the center column of a 7x7 grid similar to a 49-way joystick.  Values between 577 and  641 would be one column to the right of center.  You can adjust the ranges as desired for a larger deadzone or more sensitivity.

You can write the code for absolute position or relative position.

Absolute position -- If you move from column 3-Right to 2-Right, it will send one left keystroke. This option is not usually used.

Relative position -- If you stay centered, no keystrokes are sent. If you move the stick to a non-centered column it starts sending the desired number and rate of keystrokes.


Scott
Title: Re: U-HID Convert analog inputs to keypress?
Post by: BadMouth on March 09, 2024, 01:07:41 pm
Simplest route is probably a program called x360ce that allows you to map anything to any input on a virtual xbox360 controller.  (Analog input to D-pad for example)

There have been keyboard versions, but they weren't as universally compatible.

There are probably other solutions, but I haven't messed with this stuff for a long time.
Title: Re: U-HID Convert analog inputs to keypress?
Post by: mako_cc on March 09, 2024, 05:22:49 pm
Thank you guys very much for the replies.  My application is actually for linux (raspberry pi), so my options for SW are different.  I am looking into using qjoypad which looks promising, but I do not have my analog input device in hand yet to test with.

Thanks,
Chad
Title: Re: U-HID Convert analog inputs to keypress?
Post by: BadMouth on March 16, 2024, 09:18:41 am
Was researching something else and came across this which may be of use if you haven't already found a solution: https://hackaday.io/project/194875-picogamepadcoverter