Here it is. Part 2 of using PS3 remote with Ubuntu. In this part I will finally show you how to do something useful with remote. So, here is what we want to control with remote:

  • multimedia keys: previos/next song, up/down volume
  • cycle thru opened windows with alt-tab
  • open/close applications (music player, tv application, …)
  • whatever else you want and is controllable with keyboard or from script

Let’s get to work. I assume you have done all the “work” from part 1. If not, do it now. Next, we need library to emulate keyboard keypresses:


sudo apt-get install python-virtkey

I wrote a small wrapper around python-virtkey for easier using. Download it from github. Also, download all other scripts from there because we gonna need them in couple of minutes.

Using VirtualKey:
You’ll be using three methods from VirtualKey: press_key, hold_key, release_key, toggle_key. Hold_key is method for pressing some key and holding it pressed. Release_key is for releasing pressed key. Press_key is like you pressed some key and immediately after that released it. Small examples:


from virtualkey import VirtualKey
keys = VirtualKey()
# pressing "a" button
keys.press_key("a")
# pressing ctrl-c (holding control while pressing "c")
keys.press_key(["ctrl_left", "c"])
# holding alt and pressing tab
keys.toggle_key("alt_left")
keys.press_key("tab");
keys.press_key("tab");
keys.toggle_key("alt_left")

You can try example script (also from ps3bdremote github) which demonstrate how to use VirtualKey:


python virtualkey-test.py

Using remote:
ps3bdremote-thumbFinally, let’s map keys to remote so we can use it. On the left picture (click to zoom it) you can see how I mapped keys. You can, of course, change it as you like.

Enough talking, let’s test it!


python ps3-remote.py

You can add additional “actions”:


elif command == "stop":
   keys.press_key("xf86audiostop")

All key definitions are in virtualkey.py file.

Known issues:

  • pairing - you still need to pair with remote before using. If you know how to solve this, please help :) and leave a comment
  • alt+tab - you’ll have to use two keys for alt+tab. First, press square as this holds alt key. After that, press triangle which simulates pressing tab key. Press square again to release pressed alt. This has to be done this way because there is no information from remote what key is released, just that some key is released

So, this is it. Download scripts from github and enjoy. Again, your feedback is very appreciated. If you like or hate this script(s), leave a comment ;) Also, If you want to help and improve scripts. Thanks!