Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: U-HID Convert analog inputs to keypress?  (Read 567 times)

0 Members and 1 Guest are viewing this topic.

mako_cc

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 2
  • Last login:March 12, 2024, 07:40:40 pm
  • I want to build my own arcade controls!
U-HID Convert analog inputs to keypress?
« 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

PL1

  • Global Moderator
  • Trade Count: (+1)
  • Full Member
  • *****
  • Online Online
  • Posts: 9405
  • Last login:Today at 10:18:34 am
  • Designated spam hunter
Re: U-HID Convert analog inputs to keypress?
« Reply #1 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.

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

BadMouth

  • Trade Count: (+6)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 9226
  • Last login:Yesterday at 03:37:41 pm
  • ...
Re: U-HID Convert analog inputs to keypress?
« Reply #2 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.

mako_cc

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 2
  • Last login:March 12, 2024, 07:40:40 pm
  • I want to build my own arcade controls!
Re: U-HID Convert analog inputs to keypress?
« Reply #3 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

BadMouth

  • Trade Count: (+6)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 9226
  • Last login:Yesterday at 03:37:41 pm
  • ...
Re: U-HID Convert analog inputs to keypress?
« Reply #4 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