Skip to content

Instantly share code, notes, and snippets.

@gatopeich
Created February 5, 2023 16:33
Show Gist options
  • Save gatopeich/8770b1c4ef96cb8d576fbf03bee0c355 to your computer and use it in GitHub Desktop.
Save gatopeich/8770b1c4ef96cb8d576fbf03bee0c355 to your computer and use it in GitHub Desktop.
Sample gamepad configuration Xorg with hints to use as Mouse+Keyboard for Minecraft
# Gamepad configuration for general use, and emulating mouse+keys for Minecraft
Section "InputClass"
Identifier "Gamepads"
Driver "joystick"
MatchIsJoystick "on"
#MatchDevicePath "/dev/input/js*"
#MatchProduct "GAME"
# Map arrow pad (axis 5 & 6) to cursor keys left right up down
Option "MapAxis5" "keylow=113 keyhigh=114"
Option "MapAxis6" "keylow=111 keyhigh=116"
Option "AutoRepeat" "0 0"
# Map buttons to mouse left, Q, mouse right, E, ...
# On my PSX-style gamepad they are Square, Cross, Circle, Triangle, L, R, Select, Start
# On Minecraft I want L-Click (Attack), drop, R-click (Use), Inventory, Sneak, Jump, Sprint, Enter,
# 9=Select=Esc, START=F5, 11=L3=Pick, 12=R3=Emote, 13 = HOME
# OLD: Option "ButtonMapping" "1 24 3 26 50 65 37 36 9 71 2 45 110"
Option "MapButton1" "button=1" # L-Click ~ Attack
Option "MapButton2" "key=24" # Q ~ drop
Option "MapButton3" "button=3" # R-Click ~ Use
Option "MapButton4" "key=26" # E ~ Inventory
Option "MapButton5" "key=50" # Shift ~ Sneak
Option "MapButton6" "key=65" # Space ~ Jump
Option "MapButton7" "key=37" # Control_L ~ Sprint
Option "MapButton8" "key=36" # Enter
Option "MapButton9" "key=9" # Escape
Option "MapButton10" "key=71" # F5 ~ Toggle Perspective
Option "MapButton11" "button=2" # Middle-click ~ Pick block
Option "MapButton12" "key=45" # K ~ Emote
Option "MapButton13" "key=110" # Home key
EndSection
# Relevant keycodes scanned with
#$ xev | grep -A2 --line-buffered '^KeyRelease' | sed -n '/keycode /s/^.*keycode \([0-9]*\).* (.*, \(.*\)).*$/\1 \2/p'
# 1 => mouse 1 ~ Attack
# 24 q => Drop item mapped to PSX Cross
# 3 => mouse 3 ~ Use
# 26 e => Inventory mapped to PSX Triangle
# 50 Shift_L ~ Sneak
# 65 space ~ Jump
# 37 Control_L ~ Sprint
# 36 Return
# 9 Esc
# 71 F5 => Toggle Perspective
# 2 => Mouse middle ~ Pick block
# 56 b ~ Emote
# 25 w
# 38 a
# 39 s
# 40 d
# 53 x
# 45 k
# 62 Shift_R
# 110 Home
# 64 Alt_L
# 111 Up
# 116 Down
# 113 Left
# 114 Right
@gatopeich
Copy link
Author

And this is the output of xinput list-props after loading with that configuration, which could be used to enable the same mappings via xinput command line...

Device 'ACRUX USB GAME PAD':
	Device Enabled (116):	1
	Coordinate Transformation Matrix (118):	1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
	Device Accel Profile (279):	0
	Device Accel Constant Deceleration (280):	1.000000
	Device Accel Adaptive Deceleration (281):	1.000000
	Device Accel Velocity Scaling (282):	10.000000
	Debug Level (283):	0
	Buttons (284):	13
	Axes (285):	6
	Generate Mouse Events (286):	1
	Generate Key Events (287):	1
	Axis Deadzone (288):	5000, 5000, 5000, 5000, 5000, 5000
	Axis Type (289):	1, 1, 1, 1, 3, 3
	Axis Mapping (290):	1, 2, 3, 4, 6, 6
	Axis Amplify (291):	1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000
	Axis Keys (low) (292):	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 113, 0, 0, 0, 111, 0, 0, 0
	Axis Keys (high) (293):	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 0, 0, 0, 116, 0, 0, 0
	Button Mapping (294):	5, 6, 5, 6, 6, 6, 6, 6, 6, 6, 5, 6, 6
	Button Number (295):	1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0
	Button Amplify (296):	1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000
	Button Keys (297):	0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 50, 0, 0, 0, 65, 0, 0, 0, 37, 0, 0, 0, 36, 0, 0, 0, 9, 0, 0, 0, 71, 0, 0, 0, 0, 0, 0, 0, 45, 0, 0, 0, 110, 0, 0, 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment