HackSoton 3

They had Bacon, It was awesome.

26 February 2014

It was time for another Hacksoton, and after the fun I'd had at the previous event I was certain I was going to this one too. Fortunately, I was quite quick at nabbing a ticket as they were sold out before too long. Unlike last time, I decided that I'd like to actually try and make something that at least had the potential to work. I had a few ideas I thought about cracking on with so I figured I'd pick one on the day.

A screenshot of QWOP

While catching the train to Southampton with Beth and Paul we were all bouncing around the different ideas we had. Somehow we got talking about Twitch play Pokemon and I think it was Paul that mentioned how frustrating it would be to apply the same Twitch dynamic to the Flash game QWOP. If you've not heard of QWOP go play it, It is frustrating - so naturally a few dozen people playing it at the same time would make it easier, right? Wisdom of crowds and all that.

So, first thing we did was look into how we might tie multiple people into one version of the game. Tying people together is the (relatively) easy part, simple Websockets server should deal with that, The tricky part was the keyboard events. At first we thought we might be able trigger keyboard commands using a Javascript plugin but that didn't work (On further reading since, I think this should be workable - but I need to sit down and try it at some point). It was at this point that Brandon popped on over and asked what we were doing and whether he could join us. Of course! It's a hack day, Let's collaborate! I remembered that Brandon had made a bad keyboard in the past. This keyboard was made using an Arduino that (I think) used a custom bootloader to make the OS think it was a PS/2 connected keyboard. Great, that should let us control the game. At this point, Brandon and Paul looked into connecting everybody's mobile phones together with Socket.io I looked into getting the Node server that they'd be building talking to the Arduino as I'd had a little experience with that sort of thing in the past.

Getting Arduinos to behave is always a tricky business - when things go wrong I liken it to trying to fix a leaky pipe in a house you can't get inside of. And, as is always the way when you have limited time, nothing was behaving. We were using node-serialport to connect to our Arduino Uno with a Serial connection to try and get it to dispatch keypresses. I've used this library for almost every single project I've used a serial port connection with, I even based my own Chrome OS serial library on it - but this time I just could not get it to behave. Something kept triggering the Arduino twice, I still don't know what but I do intend to revisit.

Once I'd managed to wrangle to Arduino/Node server together in an amicable way, it was Brandons turn, himself also an Arduino enthusiast, to have the Arduino dispatch the keypresses. Unfortunately, it became apparent at this point that the two different softwares weren't compatible. Bummer, But hey, we couldn't have tested for this before then and it's a hack day - it doesn't matter, Lot's of things don't work. By this point, Both Brandon and Paul had put together a really nice Front-end for the Node server to allow people to send the key they thought should be pressed in the game. It would be a massive shame to let all that work go unnoticed, so we started looking at other ways to dispatch key events. Bare in mind - the presentations had already started by this point and our turn was coming up soon.

We all started frantically Googling for ways to programmatically dispatch keypresses on a Mac OS. I started looking into controlling Java robots, Selenium was suggested by Tom who had popped over to see how we were doing and Brandon hit on dispatching events using Applescript. Applescript? Perfect, There's no reason why that shouldn't work. So I started looking into implementing that alongside Brandon.

After around ten minutes I'd managed to get Applescript dispatching key events. Excellent, we're sorted! It'll work! Except... I couldn't find a list of keycodes and Applescript keycodes, it seems, aren't like a lot of others. So now I'm at the point where I'm manually telling the Node.js server to dispatch a random keycode, see what happens and then adjust. I think we were like 5 slots from being on stage so I imagine that looked something like this.

Eventually, we got the QWOP keys we needed and gave it a shot. It actually worked! Brandon and Paul were able to type the set keys on my Mac from their phones and control the game. Sorted. We'd actually managed to tape together a working prototype in less than 9 hours. We sat back and waited for our turn to display. Our turn came, we went on up to show, plugged in the screen and... nothing happened (which seems to happen every time with me). Never mind, there's always next time, but why hadn't it worked? Tom explained to me afterwards that plugging in a second screen (the projector in this case) might have reset how Applescript talked to certain applications meaning that Firefox needed a restart. I'll remember that for another day

And that's that, I had a great time, Our project sort of works (and you can grab it here) and as always I got to meet a ton of great, talented people.

Bring on HackSoton 4.