Difference between revisions of "Lazarus IDE with Gamepad on Linux"

From Lazarus wiki
Jump to navigationJump to search
(Initial text.)
 
m (Minor typos.)
Line 1: Line 1:
On occasion, particularly if exploring rarely-visited legacy code, it might be necessary to do an inordinate amount of single stepping. Particularly if afflicted with some degree of RSI, continual use of a PC keyboard's function keys- not to mention obscure control combinations- can become surprising uncomfortable; users with chilly workrooms might also appreciate a solution that allows them to keep their hands under a blanket or inside the sleeves of a dressing gown.
+
On occasion, particularly if exploring rarely-visited legacy code, it might be necessary to do an inordinate amount of single stepping. Particularly if afflicted with some degree of RSI, continual use of a PC keyboard's function keys- not to mention obscure control combinations- can become surprisingly uncomfortable; users with chilly workrooms might also appreciate a solution that allows them to keep their hands under a blanket or inside the sleeves of a dressing gown.
  
 
There are many utility programs on both Windows and Linux that map events from various kinds of game controller to the keyboard. However many of these, not to mention hardware solutions like the Logitech G600 gamer's mouse, are unable to generate function key presses and releases qualified by the control key etc. On Linux it is possible instead to map events either at the kernel or at the X11 level, neither is particularly well documented and it is possible to end up- particularly in the X11 case- having to use one program to detect an event and a separate one to emit a keyboard sequence.
 
There are many utility programs on both Windows and Linux that map events from various kinds of game controller to the keyboard. However many of these, not to mention hardware solutions like the Logitech G600 gamer's mouse, are unable to generate function key presses and releases qualified by the control key etc. On Linux it is possible instead to map events either at the kernel or at the X11 level, neither is particularly well documented and it is possible to end up- particularly in the X11 case- having to use one program to detect an event and a separate one to emit a keyboard sequence.
Line 63: Line 63:
 
  # the raw events, and then refer to codes.c in the mxk source.
 
  # the raw events, and then refer to codes.c in the mxk source.
 
   
 
   
Save that as /etc/gamepad-to-Lazarus.mxk, it may be used both a script and a configuration file.
+
Save that as /etc/gamepad-to-Lazarus.mxk, it may be used both as a script and a configuration file.
  
  
 
MXK is sufficiently flexible that it should be possible to map the direction controller such that- for example- the breakpoint and call stack pages popped up, but that is left as an exercise for the reader.
 
MXK is sufficiently flexible that it should be possible to map the direction controller such that- for example- the breakpoint and call stack pages popped up, but that is left as an exercise for the reader.
  
With thanks to Neal Stephenson's "Dr. X" for the initial inspriation.
+
With thanks to Neal Stephenson's "Dr. X" for the initial inspiration.
  
 
[[Category:Lazarus]]
 
[[Category:Lazarus]]

Revision as of 23:10, 26 January 2019

On occasion, particularly if exploring rarely-visited legacy code, it might be necessary to do an inordinate amount of single stepping. Particularly if afflicted with some degree of RSI, continual use of a PC keyboard's function keys- not to mention obscure control combinations- can become surprisingly uncomfortable; users with chilly workrooms might also appreciate a solution that allows them to keep their hands under a blanket or inside the sleeves of a dressing gown.

There are many utility programs on both Windows and Linux that map events from various kinds of game controller to the keyboard. However many of these, not to mention hardware solutions like the Logitech G600 gamer's mouse, are unable to generate function key presses and releases qualified by the control key etc. On Linux it is possible instead to map events either at the kernel or at the X11 level, neither is particularly well documented and it is possible to end up- particularly in the X11 case- having to use one program to detect an event and a separate one to emit a keyboard sequence.

The example below uses the MXK program http://welz.org.za/projects/mxk to map eight buttons from an NES-style gamepad https://en.wikipedia.org/wiki/File:Super-Famicom-Controller.jpg to the key combinations most commonly used during debugging.


#!/usr/local/bin/mxk -dzp

# Experimental mapping from gamepad to Lazarus debugger. Invoke like
#
# mxk -dzp /etc/gamepad-to-Lazarus.mxk
#
# Terminate by running interactively using  mxk -a  and issuing the halt
# command. MarkMLl.

# L-shoulder    top2            Run             F9
# R-shoulder    pinkie          Stop            Ctrl + F2
# Select        base3           Compile         Ctrl + F9
# Start         base4           Build           Shift + F9
# X             trigger         Step over       F8
# Y             top             Step into       F7
# A             thumb           Step out        Shift + F8
# B             thumb2          Step to cursor  F4

# Note that Lazarus's default Stop Ctrl + F2 clashes with KDE's System Settings
# -> Shortcuts -> Global Shortcuts -> System Settings -> Switch to Desktop 2.

name-source 0 usb gamepad
start-array 0

press-array 0 top2 f9/press sync:
release-array 0 top2 f9/release sync:

press-array 0 pinkie leftcontrol/press f2/press sync:
release-array 0 pinkie f2/release leftcontrol/release sync:

press-array 0 base3 leftcontrol/press f9/press sync:
release-array 0 base3 f9/release leftcontrol/release sync:

press-array 0 base4 leftshift/press f9/press sync:
release-array 0 base4 f9/release leftshift/release sync:

press-array 0 trigger f8/press sync:
release-array 0 trigger f8/release sync:

press-array 0 top f7/press sync:
release-array 0 top f7/release sync:

press-array 0 thumb leftshift/press f8/press sync:
release-array 0 thumb f8/release leftshift/release sync:

press-array 0 thumb2 f4/press sync:
release-array 0 thumb2 f4/release sync:

start-target 0 key:f2 key:f4 key:f7 key:f8 key:f9 key:leftshift key:leftcontrol
connect-node source:0 array:0
connect-node array:0 target:0
lock-source 0

# The key/button allocation and names will depend very much on the input device,
# and with cheap Chinese peripherals will be anybody's guess. Use evtest to see
# the raw events, and then refer to codes.c in the mxk source.

Save that as /etc/gamepad-to-Lazarus.mxk, it may be used both as a script and a configuration file.


MXK is sufficiently flexible that it should be possible to map the direction controller such that- for example- the breakpoint and call stack pages popped up, but that is left as an exercise for the reader.

With thanks to Neal Stephenson's "Dr. X" for the initial inspiration.