How To Use A Nintendo Wii Controller To Play Linux Games

Play Linux Games With A WII Controller
Play Linux Games With A WII Controller.

One of those myths that perpetually circulate is that there are no good games for Linux. In a recent article, I showed the best ways to install and play games within Linux. I have also written an article highlighting the best Linux Games Emulators.

A key part of playing games is obviously being able to control the characters, ships, bats, tanks, cars or other sprites.

The Nintendo WII controller is great for playing games, especially when using old school emulators and the Internet Archives Internet Arcade games.

The Nintendo WII was a really popular games console when it was first released and for many people, it now sits gathering dust next to the DVD player. Rather than buy a dedicated game controller for playing games on your Linux machine why not just use the WII Remote.

Of course, the WII controller isn't the only controller you are likely to have to hang around and I will be writing guides for XBOX controllers and even the OUYA controller soon.

One advantage of the WII controller is the dpad. It works much better for old school games than the XBOX controller because it isn't quite so sensitive.

Unfortunately for those of you afraid of the command line there is much terminal work to be performed but fear not as I will do my best to explain everything you need to do to get the WII controller working.

Install The Linux Software Required To Use A Wii Controller

The applications you need to install are as follows:

This guide assumes you are using a Debian-based distro such as Debian, Mint, Ubuntu etc. If you are using an RPM based distro use YUM or a similar tool to get these applications.

Type the following to get the applications:

sudo apt-get install lswm wminput libcwiid1

Find The Bluetooth Address Of Your WII Controller

The whole reason for installing lswm is to get the bluetooth address of your WII controller.

Within the terminal type the following:

lswm

The following will be displayed on the screen:

"Put Wiimotes in discoverable mode now (press 1+2)..."

Do as the message asks and hold the 1 and 2 buttons on the WII controller at the same time.

If you did it correctly a set of numbers and letters should appear along the lines of this:

00:1B:7A:4F:61:C4

If the letters and numbers don't appear and you find yourself back at the command prompt run lswm again and try pressing 1 and 2 together again. Basically, keep trying until it works.

Set Up The Game Controller

To use the WII Controller as a gamepad you will need to setup a configuration file to map the buttons to keys.

Type the following into the terminal window:

sudo nano /etc/cwiid/wminput/gamepad

 

This file should already have some text in it along the lines of this:

# gameport
Classic.Dpad.X = ABS_X
Classic.Dpad.Y = ABS_Y
Classic.A = BTN_A

You will need to add some more lines to this file to get the gamepad working the way you want it to.

The basic format of each line in the file is WII Controller button on the left and the keyboard button on the right.

For example:

Wiimote.Up = KEY_UP

The above command maps the up button on the WII remote to the up arrow on the keyboard.

Here is a quick tip. The WII remote is usually on its side when you are playing games and so the up arrow on the Wii remote actually needs to map to the left arrow on the keyboard.

At the end of this article, I will list all the possible WII mappings and a range of sensible keyboard mappings.

For now though here is a quick and simple set of mappings:

Wiimote.Up = KEY_LEFT

Wiimote.Down = KEY_RIGHT

Wiimote.Left = KEY_DOWN

Wiimote.Right = KEY_UP

Wiimote.1 = KEY_SPACE

Wiimote.2 = KEY_LEFTCTRL

Wiimote.A = KEY_LEFTALT

Wiimote.B = KEY_RIGHTCTRL

Wiimote.Plus = KEY_LEFTSHIFT

The above maps the left arrow key on the keyboard to the up button on the WII controller, the right key to the down button the down arrow to the left button, the up arrow to the right button, the space bar as button 1, the left CTRL key on the keyboard to the 2 button, the left ALT key to the A button, the right CTRL key as the B button and the left shift key as the Plus button.

If you are using retro games from the internet archive arcade they will generally say what keys need to be mapped. You can have different gamepad files for different games so that you can just use the WII keypad setup for each game.

If you are using emulators for old games consoles such as the Sinclair Spectrum, Commodore 64, Commodore Amiga and Atari ST then the games often let you remap the keys and you can, therefore, map the game keys to your gamepad file.

For more modern games they often allow the use of the mouse to control them or even keys so you can set your gamepad file up to match the keys required to play the games.

To save the gamepad file press CTRL and O at the same time. Press CTRL and X to exit nano.

Connect The Controller 

To actually connect the controller so that it uses your gamepad file run the following command:

sudo wminput -c /etc/cwiid/wminput/gamepad

You will be asked to press the 1 + 2 keys at the same time to pair the controller with your computer.

The word "ready" will appear if your connection has been successful.

Now all you have to do is start the game you wish to play.

Enjoy!!!

Appendix A - Possible WII Remote Buttons

The following table shows all the WII remote buttons that can be set up within your gamepad file:

  • Wiimote.Up
  • Wiimote.Down
  • Wiimote.Left
  • Wiimote.Right
  • Wiimote.A
  • Wiimote.B
  • Wiimote.1
  • Wiimote.2
  • Wiimote.Plus
  • Wiimote.Minus
  • Wiimote.Home
  • Wiimote.Dpad.X
  • Wiimote.Dpad.Y
  • Nunchuk.C
  • Nunchuk.Z
  • Nunchuk.Stick.X
  • Nunchuk.Stick.Y
  • Classic.Up
  • Classic.Down
  • Classic.Left
  • Classic.Right
  • Classic.Minus
  • Classic.Plus
  • Classic.Home
  • Classic.A
  • Classic.B
  • Classic.X
  • Classic.Y
  • Classic.ZL
  • Classic.ZR
  • Classic.L
  • Classic.R
  • Classic.Dpad.X
  • Classic.Dpad.Y
  • Classic.LStick.X
  • Classic.LStick.Y
  • Classic.RStick.X
  • Classic.RStick.Y
  • Classic.LAnalog
  • Classic.RAnalog

Appendix B - Keyboard Mappings

This is a list of sensible keyboard mappings

Potential Nintendo WII Controller To Keyboard Mappings
KeyCode
EscapeKEY_ESC
0KEY_0
1KEY_1
2KEY_2
3KEY_3
4KEY_4
5KEY_5
6KEY_6
7KEY_7
8KEY_8
9KEY_9
- (minus symbol)KEY_MINUS
= (equals symbol)KEY_EQUAL
BackSpaceKEY_BACKSPACE
TabKEY_TAB
QKEY_Q
WKEY_W
EKEY_E
RKEY_R
TKEY_T
YKEY_Y
UKEY_U
IKEY_I
OKEY_O
PKEY_P
[KEY_LEFTBRACE
]KEY_RIGHTBRACE
Enter KEY_ENTER
CTRL (Left side of keyboard)KEY_LEFTCTRL
AKEY_A
SKEY_S
DKEY_D
FKEY_F
GKEY_G
HKEY_H
JKEY_J
KKEY_K
LKEY_L
; (Semi Colon)KEY_SEMICOLON
' (Apostrophe)KEY_APOSTROPHE)
# 
Shift (Left side of keyboard)KEY_LEFTSHIFT
\KEY_BACKSLASH
ZKEY_Z
XKEY_X
CKEY_C
VKEY_V
BKEY_B
NKEY_N
MKEY_M
, (comma)KEY_COMMA
. (full stop)KEY_DOT
/ (forward slash)KEY_SLASH
Shift (right side of keyboardKEY_RIGHTSHIFT
ALT (left side of keyboard

KEY_LEFTALT

Space barKEY_SPACE
Caps LockKEY_CAPSLOCK
F1KEY_F1
F2KEY_F2
F3KEY_F3
F4KEY_F4
F5KEY_F5
F6KEY_F6
F7KEY_F7
F8KEY_F8
F9KEY_F9
F10KEY_F10
F11KEY_F11
F12KEY_F12
Num KockKEY_NUMLOCK
Shift LockKEY_SHIFTLOCK
0 (keypad)KEY_KP0
1 (keypad)KEY_KP1
2 (keypad)KEY_KP2
3 (keypad)KEY_KP3
4 (keypad)KEY_KP4
5 (keypad)KEY_KP5
6 (keypad)KEY_KP6
7 (keypad)KEY_KP7
8 (keypad)KEY_KP8
9 (keypad)KEY_KP9
. (keypad dot)KEY_KPDOT
+ (keypad plus symbol)KEY_KPPLUS
- (keypad minus symbol)KEY_KPMINUS
Left arrowKEY_LEFT
Right arrowKEY_RIGHT
Up arrowKEY_UP
Down arrowKEY_DOWN
HomeKEY_HOME
InsertKEY_INSERT
DeleteKEY_DELETE
Page UpKEY_PAGEUP
Page DownKEY_PAGEDOWN