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.
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.
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.