Maybe, just maybe, this post from how to add a physical button to extruder motor control? #10394 could help (the emphasis is mine):
rather than directly work on stepper.cpp, I would rather suggest to take a look at the LCD control part, and integrate an emulation of the prepare/move/Z-axis code. As for accessible pins, perhaps use any unused endstop ones ?
This would make sense, as it is similar to the location (i.e. file(s)) that required changing for 0scar's question Can G-code scripts be run automatically on inserting an SD card when using Marlin Firmware?. The file in that case was
ultralcd.cpp (see my answer).
ultralcd.cpp seems to have been either removed, moved or renamed to
ultralcd_st7920_u8glib_rrd_AVR.cpp. It doesn't look hopeful. Previously it was in a 3rd part bugfix, see this answer, and the link of that
ultralcd.cpp is now dead.
Alternatively, this post helpfully suggests:
This is not a feature we would add. But it's possible to do movement with buttons by hooking into the LCD code and following the technique currently used for the KEYPADs.
So, that would seem to be a promising place to start. I'm not (currently) sure which file(s) that is though. It might be the code that handles the RepRapWorld keypad (see below).
This could also be useful, the RepRapWorld Keypad:
Hook it up to your RAMPS AUX-2 port. Configure the firmware to use the keypad. The keypad is fully supported in Marlin Firmware.
You could emulate (i.e. reverse engineer) this piece of simple hardware (the most complex IC on it is just a shift register) and use the already built in code.
FWIW, a similar sounding (9 button) keypad is referenced here, Adding custom keypad, marlin
However, upon further reading, it is unclear whether the RepRapWorld keypad is still supported, see Feature request: add suppport for reprapworld keypad #1142. Apparently RepRapWorld didn't (6 years ago) support it nor supply the source and expected the Marlin coders to support it for free.
Other references and links
Nevertheless, the following post also suggests other sources of information that could be of use:
For best results getting help with configuration and troubleshooting,
please use the following resources:
After seeking help from the community, if the consensus points to to a
bug in Marlin, then you should post a bug report.
It should be noted that, as a rule, the Marlin people prefer potential issues to be discussed on the Firmware Forum first, before any bug report or feature request is submitted to Github. This is to stop their Github issues page for getting too cluttered.
Also note that Tom's 3D Forums are now dead.
See also Marlin/ LCD-Keypad Code Mod, although the thread seems to consist mostly of posts bemoaning software maintenance and life-cycles, and then sort of loses steam and dies at the end. However, this post mentions