Wireless remote control
From Evan Sultanik
The following is a very simple application for remote controlling one's computer over a possibly wireless network. The intended use is for clicking through the slides of presentations. The "clicker" can be any device that has a web browser and a network connection to the computer being controlled (i.e. your laptop hooked up to a projector). In other words, this lets one use his or her iPhone, iPod Touch or any WiFi enabled smart phone as a wireless remote control for giving presentations! The best part is that it doesn't require any special software installation on the phone.
For the story of how I was inspired to write this app, check out the related blog post.
Contents |
Dependencies
The following are all required on the computer that is to be controlled:
For the controller (i.e. phone):
- a web browser; and
- a network connection to the controlled computer.
The program
The program works by creating a web server on the presentation computer. The remote controller navigates to the web server and is presented with a set of buttons to, among other things, send the page up and page down key events to the presentation computer to advance slides.
The program consists of two files: control.pl (the controller code) and control.html (the webpage that the webserver will host).
control.pl
#!/usr/bin/perl -w use HTTP::Daemon; use HTTP::Status; my $port = 80; my $file = "control.html"; # Replace this with the absolute path to the HTML file my $d = HTTP::Daemon->new(LocalPort => $port) || HTTP::Daemon->new() || die; print "Server running at: ", $d->url, "\n"; while(my $c = $d->accept) { while(my $r = $c->get_request) { if($r->method eq 'POST') { my $url = $r->content; $url =~ s/^\///; my $cmd = ""; my $arg = ""; $cmd = $1 if($url =~ m/cmd=([^&]*)&?/); $arg = $1 if($url =~ m/arg=([^&]*)&?/); $arg =~ s/\+/ /g; $arg =~ s/"/\\"/g; my $command = ""; $command = "type \"$arg\"" if($cmd eq "type"); $command = "click 1" if($cmd eq "click"); $command = "mousemove_relative " . $arg if($cmd eq "mmr"); $command = "key Prior" if($cmd eq "pgup"); $command = "key Next" if($cmd eq "pgdown"); system("xdotool " . $command) if(!($command eq "")); } if($r->method eq 'GET' || $r->method eq 'POST') { $c->send_file_response($file); } else { $c->send_error(RC_FORBIDDEN) } } $c->close; undef($c); }
control.html
<html> <head> <title>Evan's Remote Control App</title> <meta name="viewport" content="initial-scale=1.5, user-scalable=no" /> </head> <body> <form name="click" action="/" method="POST"> <input type="hidden" name="cmd" value="click" /> <input type="submit" value="Click" /> </form><br /> <form name="pgup" action="/" method="POST"> <input type="hidden" name="cmd" value="pgup" /> <input type="submit" value="PgUp" /> </form><br /> <form name="pgdn" action="/" method="POST"> <input type="hidden" name="cmd" value="pgdown" /> <input type="submit" value="PgDn" /> </form><br /> <form name="type" action="/" method="POST"> <input type="hidden" name="cmd" value="type" /> <input type="text" name="arg" /> <input type="submit" value="Type" /> </form> </body> </html>
Example
First, we start the controller on the presentation computer. The program will first try to run on port 80 (which usually requires root privileges). If it cannot start on port 80 then it chooses the first open port it finds.
$ ./control Server running at: http://129.25.27.184:56086/
Here, since the server was not run as root, it chose to run on port 56086.
Now all we have to do is navigate to the server from our phone!
It's not pretty, but it's functional! If you are willing to spend more than the 10 minutes on this that I spent, you can beautify the .html code all you'd like.
