Sisk has asked for the wisdom of the Perl Monks concerning the following question:

I need some help. I've got a little Perl app meant to navigate through my ROM collection and launch the games in whatever emulator is appropriate for that game. I've been using it for years, but I now have a computer dedicated to my ROM collection and hooked up to my TV and would like very much to not have a keyboard and mouse hooked up to it.

My question is this: is there a way to navigate through a TK listbox using a joystick/gamepad? Ideally I'd like to be able to use one axis for each listbox and a button on the gamepad to trigger the function that lauches the game. This is the only obstacle left keeping me from doing away with the keyboard and mouse. I've looked at a couple joystick libraries but I haven't had any luck. If it makes a difference, this app is running on a Debian GNU/Linux box.

Replies are listed 'Best First'.
Re: TK Listbox and gamepads
by zentara (Cardinal) on Oct 18, 2010 at 19:53 UTC
    <brainstorm>

    I might go with a more active toolkit for joystick, like maybe gtk+ joystick lib. No one has done it yet, but it may be a good candidate for a Perl module to access the lib. Then conceivably the joystick actions would become part of the PerlGtk bindings. (I would go to the Perl/Gtk2 maillist and ask/beg :-) )

    As long as you can get the joystick to show up in /dev/input as /dev/js0 ( or something similar), you could use Perl to read the device and translate it's binding to something Tk uses.

    </brainstorm>


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: TK Listbox and gamepads
by thundergnat (Deacon) on Oct 18, 2010 at 18:11 UTC

    I have never done this so take this with a grain of salt.

    You are going to need some kind of device driver for the joystick/gamepad that remaps the device inputs to standard x-events. xserver-xorg-input-joystick seems like a likely candidate. Set up your mappings, then bind the appropriate actions to those mappings. See perdoc Tk::bind and perldoc Tk::event for details.

      This does what I was wanting and more now that I've had time to sit down and mess with it. xserver-xorg-input-joystick allows me to set up my gamepad as a mouse at the OS level. I mapped one of the sticks and a couple of the buttons I don't use in my emulators as mouse functions and it works beautifully. Thanks.
Re: TK Listbox and gamepads
by aquarium (Curate) on Oct 19, 2010 at 01:09 UTC
    a remote possibility (pun inintended) could be one of those gamers/numeric keypads. they're small and naturally could be used in the games if they use the standard numeric keypad mappings for directions.
    the hardest line to type correctly is: stty erase ^H
      another possibility just thought of: most tv / radio cards come with a infrared module and a remote. linux has a standard kernel module for IR..and then you just interface to it with perl, something along the lines of http://www.thekramers.net/ir/
      check out the debian hardware compatibility list to obtain a supported TV/radio tuner with IR.
      the hardest line to type correctly is: stty erase ^H
        Actually I have an ATI remote that's fully supported by Debian that I thought about using. I'd rather just have the gamepad, but the remote idea is my fallback. Remotes have a tendancy to go missing in my house though. Apparently the shorter portion of the local population thinks they look an awful lot like toys.