Change keyboard bindings (for games that don't support it) on Linux

So I wanted to play EDGE. In this game all you do is move in 4 diagonal directions. The original mobile game got it right: you move with the buttons 1, 4, 3, 6. For some reason, the controls for the PC remake are completely idiotic: W A S D... and there is no way to change it.

I couldn't cope with this, so I've searched for solutions. Unfortunately, all the things I found for Linux are to remap what letters or actions each key generates, but not the actual keys. As EDGE is an SDL game, it deals with the scancodes directly so nothing worked.

By accident I found setkeycodes. With it, the solution is simple:

setkeycodes 0x10 17 0x1b 32 0x28 31

This piece of code will make Q mean W, ] mean D and ' mean S (A stays the same). So the controls become Q A ] '. Look at the keyboard and see how intuitive that is.

Posted by BlaXpirit (updated ) | Comment

Using pip is easy. Even on Windows!

I'm a Linux user, and the procedure for installing Python packages there is well-defined:

  • You use your system's package manager (apt-get, yum, pacman, whatever) to install Python and pip.
  • If a Python package you need is provided by that package manager, you should most likely install it from there.
  • But what if it's not?
    • Many people think using sudo to install a package using pip or even setup.py as root will do.
    • But I think that littering your system like that is not very nice (and running arbitrary setup.py as root is very dangerous), so I just install stuff to my user directory using pip install --user.

Today, however, I wanted to introduce Python to my friend who uses Windows, and show how nice it is by example. So I needed to install flask right away. I prepared for the worst. But it turns out that Python 3.4 and PEP 453 make it very easy!

Posted by BlaXpirit (updated ) | Comment

Diffs with syntax highlight

--- example_a.py
+++ example_b.py
@@ -1,4 +1,5 @@
-def hello()
- print("Hello, World!")
+def hello(name="world")
+ name = name.upper()
+ print("Hello, {name}!".format(name))
hello()

Someone on the #pocoo channel asked if there is any way to highlight a diff between two files while keeping their original syntax highlighting as well (using Pygments).

Posted by BlaXpirit (updated ) | Comment