DevTerm’s arrows and buttons are good for navigating in command line. But they don’t react to key press.
Luckly we can borrow idea from RetroPie distribution: joy2key.py
In the following bash script, ‘joy2key.py’ will be forked and run along with Midnight Commander.
And the python script will push keycode to programs that you are using in background. So they can react to arrows and buttons without C/C++ coding.
Here is steps:
((1)) clone RetroPie repository to /home/pi/RetroPie-Setup
You don’t need to proceed the long installation process. Since we will just borrow only some scripts.
cd
git clone --depth=1 https://github.com/RetroPie/RetroPie-Setup.git
((2)) save the following script to file and run.(Actually I saved the following script to ~/.zshrc so that whenever I run ‘zsh’, Midnight commander will launch.)
#!/bin/bash
# Joystick information
export SDL_GAMECONTROLLERCONFIG="03000000af1e00002400000010010000,ClockworkPI DevTerm,platform:Linux,a:b2,b:b1,x:b3,y:b0,back:b8,start:b9,leftx:a0,lefty:a1,"
# left right up down a:<CR> b:<space> x:<F10> y:<F9>
readonly CONFIG=(kcub1 kcuf1 kcuu1 kcud1 0x0d 0x20 kf10 kf9)
readonly JOY2KEY_SCRIPTLOC="$HOME/RetroPie-Setup/scriptmodules/helpers.sh"
if [[ -f $JOY2KEY_SCRIPTLOC ]]; then
source "$JOY2KEY_SCRIPTLOC"
scriptdir="$HOME/RetroPie-Setup"
joy2keyStart ${CONFIG[@]}
else
echo "Can't import Joy2Key Script! Error!"
echo "Script not found in: $JOY2KEY_SCRIPTLOC"
sleep 5
exit 0
fi
# hide cursor
echo -en "\e[?25l"
# Run Midnight Commander.
mc "${HOME}"
# If mc is closed, then stop the joy2key process in background.
joy2keyStop
exit 0
By this simple script, we can use arrows/buttons in command line. And it may work in X-Window.
EDIT:
I found the above script does not run latest RetroPie-Setup. I’ll try to adjust with new retropie.
There is an easier way if you really don’t want the game pad to act like a game pad but send key press, take out the keyboard, return it, search foe the small switches:
The arrow key always send arrow keys?!
The switch change the gamepad into sending key event instead of joystick event, and the “D Pad” will send arrow key event, Start/Select and ABXY will send other key event.
You can try yourself really fast, it takes litteraly less than a minute to move the switch and see what it is doing.
Sorry, terminology problem (not a gamer here). I refered to the “D-Pad” as “arrow keys” because they’re keys with arrows, which is of course very ambiguous since another set of “arrow keys” is already present on the keyboard.
I wanted to use D-Pad arrows and Buttons (A/B/X/Y) in command line without X-window env.
It is quite useful for me to use them because they are at top-most in keypad. It is better than Arrows at right-bottom.
And also I can reassign custom keycode on each buttons by adjusting ascii code as arguments to joy2key_sdl.py.
And finished to setup input configuration. The configuration file genreated and saved to /opt/retropie/configs/all/retroarch-joypads/'ClockworkPI DevTerm.cfg
According to xev(1), the buttons cause these key pressed events after changing the switch:
Arrow Dpad identical to arrow key
A button equals j key
B button equals k key
X button equals nothing u key
Y button equals i key
Select button equals space bar
Start button equals Return key
Any idea what’s wrong with my X button? Will try it again after setting the switch back to default position.
Edit: after pressing the X button a bit harder for a while, it seems to equal the u key. Will take it apart and clean it a bit, hopefully improving it.
You can also use AntiMicroX (in the repos as antimicro) to configure keyboard emulation if that’s more comfortable for you. You will, however, need to ignore the rather excessive set of axis and buttons the device descriptor reports.
Not compatible with pure text mode, but if you usually just put a terminal fullscreen in X, it does the trick.
Hi, when I try to run the retropi setup I get the message 'Unknown platform - please manually set the __platform variable to one of the following", and then a long list of platforms. Did you have to do this? If so, what platform did you pick?
Because RetroPie is being actively developed, I chose to stick to specific version of Repository.
It’s hash value is “c70801758a42fc0d017d9022e68c524578602b25”.
You may have to dig into for other version.
good luck.