LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 12-11-2017, 11:17 AM   #1
bifferos
Member
 
Registered: Jul 2009
Posts: 401

Rep: Reputation: 149Reputation: 149
DPAD on Microsoft Xbox 360 controller


I wonder if anyone has come across this problem before. After plugging in my controller and doing:

modprobe xpad
modprobe joydev

sdl-jstest --test 0
tells me that everything works, however the D-PAD is recognised as a 'hat' with various different values printed for the different directions.

So I tried to run Frozen Bubble and configure it to use the controller but found it seems to not recognise any 'hat' events.

Next I installed Rejoystick to try to map the hat to some keys, however it just selects multiple axes when I move the DPAD, so I think it doesn't properly support the hat either.

I had a look at the Frozen Bubble source, but it's pretty hard for me to read with my limited Perl skills.

Is there any other solution to using the DPAD (hat) as buttons - or keys - in games?

thanks,
Biff.
 
Old 12-11-2017, 11:50 AM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,219

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309
Quote:
Originally Posted by bifferos View Post
Is there any other solution to using the DPAD (hat) as buttons - or keys - in games?
You can actually set up these overrides (joystick actions to keyboard events) in Steam, using the Big Picture Mode. Add the game to Steam as a non-Steam game first.

This is another way:

https://github.com/AntiMicro/antimicro

This was popular a couple of years ago. I recommend only using it as a last resort:

https://pingus.seul.org/~grumbel/xboxdrv/
 
1 members found this post helpful.
Old 12-11-2017, 04:47 PM   #3
bifferos
Member
 
Registered: Jul 2009
Posts: 401

Original Poster
Rep: Reputation: 149Reputation: 149
I went with a hacked up solution in the end. I got hold of the Python 'inputs' module, had a look at what the example gameport script was printing, then tried to marry this up with the kernel documentation (/usr/src/linux/Documentation/input/event-codes.txt), because that seemed to be the only place that explained about the events.

With a bit of trial-and-error I could map left and right to the z and x keys. The up and down are presumably ABS_HAT0Y.

I played around with this code, and bad things happen if you do too many release events for a key in pynput, but there seems to be no problem pushing a release event from pynput in combination with release events from the real keyboard (pressing both DPAD left + keyboard 'z' and other combinations).

Code:
#!/usr/bin/env python
#
# Remap hat L-R keys to keyboard 'z' and 'x'
# pip install inputs
# pip install pynput

from inputs import get_gamepad
from pynput.keyboard import Key, Controller

keyboard = Controller()

while 1:
	events = get_gamepad()
	for event in events:
		if event.ev_type == "Absolute" and event.code == "ABS_HAT0X":
			if event.state == -1:
				keyboard.press('z')
			elif event.state == 1:
				keyboard.press('x')
			else:   # state == 0, centre position
				if keyboard.pressed('z'):
					keyboard.release('z')
				if keyboard.pressed('x'):
					keyboard.release('x')
And Frozen Bubble is happy :-)
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Xbox 360 Controller fatalerror0x00 Slackware 9 11-24-2012 05:15 PM
LXer: Xbox 360 reset glitch hack, Xbox 360 Linux on its way? LXer Syndicated Linux News 0 08-29-2011 10:50 PM
Xbox 360 Controller - CentOS vince4amy Red Hat 2 09-30-2009 09:33 AM
I'm a Noob and i don't know how to use my Xbox 360 controller! bman000 Linux - Hardware 2 03-02-2007 03:14 AM
xbox 360 controller programming ma1069 Programming 3 01-30-2007 07:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 07:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration